How to Use Databases With SQLAlchemy  - Flask Fridays #8

How to Use Databases With SQLAlchemy - Flask Fridays #8

Codemy.com

3 года назад

87,990 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Palki Sachdeva
Palki Sachdeva - 30.10.2023 16:55

I cant see the values stored in my db!!!

Ответить
iGarrettt
iGarrettt - 29.10.2023 18:35

For others with runtime context error:
On the python shell I discovered you also need to run

from hello import app

app.app_context().push()

Then you can db.create_all()

Ответить
MDSANIMA
MDSANIMA - 25.10.2023 16:55

make the font more bigger please, now I can see 18 line of code only, I want to see 8 line

Ответить
Prajwal M.S
Prajwal M.S - 16.10.2023 15:23

I am getting this error raise RuntimeError(unbound_message) from None
RuntimeError: Working outside of application context.

This typically means that you attempted to use functionality that needed
the current application. To solve this, set up an application context
with app.app_context(). See the documentation for more information.

Ответить
Gustavo Mingo
Gustavo Mingo - 08.07.2023 23:04

Why? UnboundLocalError: local variable 'our_users' referenced before assignment!!!!
Review and repeat and find no error!

Ответить
TehPwnerer
TehPwnerer - 04.06.2023 05:16

Does everybody that uses flash just dump everything into the same damn file is there not any example anywhere at all where this isn't done cause I can't find it and it's actually quite ridiculous

Ответить
Georly Bibas
Georly Bibas - 11.05.2023 11:55

I NEED SOME SERIOUS HELP. When I entered "from hello import db" I get nothing, no response at all. no errors, but no confirmation as well and when i tried the create_all(), I got a bunch of errors. I can't proceed. I looked it up myself but I can't find anything useful. I even tried to skip using sqlite and head over the mysql one, but the same problem persist. Please help.

Ответить
Sevii
Sevii - 06.05.2023 06:34

UPDATE
I was getting errors when trying to create the database. I put this in my code:
with app.app_context():
db.create_all()
I added this (for a single run) underneath the class that defined the db.Columns().
I also may have ran db.init_app(app) in between that and the class (or at some point in cmd - importing both db and app), I don't remember where or if that helped or not.
Either way, I got it working now (5/5/23)

Ответить
Sharifa Nazari
Sharifa Nazari - 05.05.2023 10:06

while running the db.create_all() command i got the "RuntimeError: Working outside of application context". please help me out. I have been following along with the Flask Friday since day 1.

Ответить
Hoda Amz
Hoda Amz - 12.04.2023 15:18

please the winpty python command doesn't work for me !!

Ответить
Kristyna Herman
Kristyna Herman - 28.03.2023 15:58

Hi! This is really great and I am following it for my first flask app project, but I've made my databases + tables in the MySQL workbench and I'm having a lot of trouble connecting the app to my tables (i.e. sending the outputs of my form to the tables initiated in workbench). Would you please add an explanation on how to connect to an existing table (instead of creating one directly in the script)? Thanks a lot!

Ответить
KORN
KORN - 06.03.2023 14:19

thank you sir. Could you accept my request? Can you say "You are goddam right"?

Ответить
Jin
Jin - 25.12.2022 17:17

The video awesome. however, somehow i am not able to get the table displayed as i add the users and it does not get saved down. The userid is not incremental by 1 as i add user. wonder why? i am using kali-linux and code-oss

Ответить
Mohit Alamchandani
Mohit Alamchandani - 08.10.2022 16:19

Hi, I am unable to create db.. using db.create_all().... I am getting following error : " This typically means that you attempted to use functionality that needed
the current application. To solve this, set up an application context with app.app_context()." ... I have tried to use with function
def create_app():
app = Flask(__name__)
with app.app_context():
...,
but it doesnt resolve the error.. can you please help

Ответить
Parthiv Lakhani
Parthiv Lakhani - 02.08.2022 07:24

Thank You!
Please make a Complete Machine Learning Series

Ответить
MeMyselfAndBob
MeMyselfAndBob - 30.07.2022 19:52

Hi, I've tried to add "dateOfBirth = db.Column(db.DateTime)" to the Users(db.Model) class, but it doesn't work. I Googled for two days, but I cannot find a decent answer. When I change the data type to string as in "dateOfBirth = db.Column(db.String(10)" is works just fine. It seems that sqlalchemy doesn't recognise the 'datetime' data type for entering text. When I change it to "dateOfBirth = db.Column(db.DateTime, default=datetime.utcnow)" and remove the birthday text field from the form, it works fine too. I tried very possible format like "YYYY-MM-DD", "YYYY-MM-DD HH:Mi:Sc.xxxxxx" etc. but no change in result. This is the StatementError: "sqlalchemy.exc.StatementError: (builtins.TypeError) SQLite DateTime type only accepts Python datetime and date objects as input. [SQL: INSERT INTO users (created, "firstName", "lastName", "dateOfBirth", email, phone) VALUES (?, ?, ?, ?, ?, ?) [parameters: [{'email': '[email protected]', 'phone': '+112345678', 'dateOfBirth': '2001-01-01', 'lastName': 'Doe', 'firstName': 'John'}]]"
Any tips how to book more success? Thanks a lot!

Ответить
EDDIN
EDDIN - 07.07.2022 19:56

i keep getting this error
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such column: users.date_added
help plzz

Ответить