I know a little bit of flask but I'm more comfortable with laravel and it has ORM, so I was a bit hesitant to whether I should keep learning flask or jump to Django but your series convinced me to keep using flask
When running I got RuntimeError: Working outside of application context. If it's of any help, I discover somewhere else that instead of python I had to run flask shell. It worked.
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. Thats the error message i get when i ran db.create_all(). pls any solution how to add the app.app_context() to my code??
Can anyone explain why sometimes I see people creating Class properties as: id = db.Column(db.Integer, primary_key=True) and not id: Mapped[int] = mapped_column(Integer, primary_key=True) I've seen both ways used, and I have no idea when to use either.
@@kianuyepes6510 app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///todo.db' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db = SQLAlchemy(app) app.app_context().push() Run in terminal >python >>>from app import app >>>from app import db >>>db.create_all() Now it should work
I had the same problem. when you import do import app, db, User and before writing anything write app.app_context().push() now you should't get any error and you can write User.query.all()
@@simonecutrona4224 thank you veey much i have tried that it works until you create don't create an other file just for db it just works in the main file
@@simonecutrona4224 i dont get it, where do you put the line "import app, db, User"? is this in the code or within the command line where he typed "python"?
Learning SQLAlchemy has many advantages over traditional drivers. SQLAlchemy gives more Pythonic flavor and the flow of coding is completely Object Oriented, something that most developers are dead comfortable with. Also, by just changing a line of code, one can jump multiple DBs (without even changing the entire schema or learning new syntaxes). Finally, SQLAlchemy provides compile-time checks and type safety which I argue most database drivers don't.
Hi Sir, my program doesn't create a db.sqlite3 file, instead it creates a directory 'instances' with no files inside it. I mean it fails to create the said file. What might be to possible reason? Thanks
Hi. Can anyone help me with the connection string for the AZURE Sql db. I have been stuck on this for last three days. IT would be a great help if someone could guide me. Thanks in advance
Hi thanks for this video... I would like to ask you if is it possible to create the table from the python file code, instead of gettign into the terminal???: if "__name__" == "__main__": db.create_all() app.run(debug=True) For this I'm using: "mysql://root:''@localhost:3306/testflask" And my laragon local server is on
Thanks Anthony the on;y channel that covers SQLalchemy videos
oh my god, I've been stuck in the tutorial since morning, thank you for this!
I know a little bit of flask but I'm more comfortable with laravel and it has ORM, so I was a bit hesitant to whether I should keep learning flask or jump to Django but your series convinced me to keep using flask
thank you very much, man you deserve more subs.
Thank you, Anthony.
The tutorials are extremely helpful. I however couldn't access the free course on the provided link. Is it still available?
When running I got RuntimeError: Working outside of application context. If it's of any help, I discover somewhere else that instead of python I had to run flask shell. It worked.
Thanks for letting everyone know.
life Saver Brother !!!!!!!!!
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.
Thats the error message i get when i ran db.create_all(). pls any solution how to add the app.app_context() to my code??
write before db.create_all() write from app import app, db
app.app_context().push()
db.create_all()
you can add this to your __init__.py file:
with app.app_context():
db.create_all()
this should solve your problem (sorry for being late.)
you can also add app.app_context().push() under db = SQLAlchemy(app). This should also work
thank you so much bro you saved my time :)
@@kashyapkrishnar8139
Can anyone explain why sometimes I see people creating Class properties as:
id = db.Column(db.Integer, primary_key=True)
and not
id: Mapped[int] = mapped_column(Integer, primary_key=True)
I've seen both ways used, and I have no idea when to use either.
How did you activate autocomplete for SQLAlchemy in VS Code? I have no autocomplete for this package...
when " from app import db" , shows ModuleNotFoundError: No module named 'main'? help , please
I have the same problem,incase you find a solution please share and incase I get a solution I will share
I also hAve this problem
Thankyou a lot Anthony!!!!
Awesome tutorial! Thank you so much~
db.create_all() no longer works for Python3.10? It keeps talking about application context
Run Python
>>> from app import app
>>> from app import db
>>> db.create_all()
I also have the same problem
@@kianuyepes6510 app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///todo.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
app.app_context().push()
Run in terminal
>python
>>>from app import app
>>>from app import db
>>>db.create_all()
Now it should work
@@SathishKumar-zp9yg hi it doesn't work for me can you please help me out I have a deadline
@@fahadalikhan564 write app.app_context().push() below db = SQLAlchemy(app)
Is there a way to have multiple databases used?
It is what I wanted! Thanks 🙏
Thank you very much
Thanks. It was so heapfull
when I run db.create_all()
I keep running into this error: RuntimeError: Working outside of application context.
Me 2
I had the same problem. when you import do
import app, db, User
and before writing anything write
app.app_context().push()
now you should't get any error and you can write
User.query.all()
@@simonecutrona4224 thank you veey much i have tried that it works until you create don't create an other file just for db it just works in the main file
@@simonecutrona4224 thankssss
@@simonecutrona4224 i dont get it, where do you put the line "import app, db, User"? is this in the code or within the command line where he typed "python"?
What is benefit of using sqlalchemy ORM over directly using respective database driver?
We learnt SQL, now why to put effort to learn sqlalchemy?
Learning SQLAlchemy has many advantages over traditional drivers. SQLAlchemy gives more Pythonic flavor and the flow of coding is completely Object Oriented, something that most developers are dead comfortable with. Also, by just changing a line of code, one can jump multiple DBs (without even changing the entire schema or learning new syntaxes). Finally, SQLAlchemy provides compile-time checks and type safety which I argue most database drivers don't.
Hi Sir, my program doesn't create a db.sqlite3 file, instead it creates a directory 'instances' with no files inside it. I mean it fails to create the said file. What might be to possible reason? Thanks
same issue, please share if u found any sol
@@ayasalem7056
with app.app_context():
db.create_all()
Hi. Can anyone help me with the connection string for the AZURE Sql db. I have been stuck on this for last three days. IT would be a great help if someone could guide me. Thanks in advance
Unresolved attribute reference 'String' for class 'SQLAlchemy' . db.column does not recognize. Thank you
from app import db
shows
Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'app'....pls help
You probably just need to check the names of your files. I wouldn't recommend importing your db object from a file called app.py
How to write a trigger in sql alchemy.??
I found an error
flask_sqlalchemy module not found
"pip install flask-sqlachemy" should help you
Hi
thanks for this video... I would like to ask you if is it possible to create the table from the python file code, instead of gettign into the terminal???:
if "__name__" == "__main__":
db.create_all()
app.run(debug=True)
For this I'm using:
"mysql://root:''@localhost:3306/testflask"
And my laragon local server is on
not work without context.
app.app_context().push()
Thanks! Great video, very useful