Комментарии:
I am facing this problem could any one solve.... I hold here
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.
For those who have problems when using: db.create_all()
from flaskblog import db, app
app.app_context().push()
db.create_all()
.
.
.
the rest of the code should work
Try as I might, the db stuff just doesn't fly in 2023. Great video, just needs an update I guess.
Ответитьi keep geting ModuleNotFoundError: No module named 'flaskblog' i looked for a fix way in the comment and even in other tutorials but it is the same
ОтветитьI hope that one day there is a newer version of this. Everything was going great until I got to the sql lite stuff, lol. I have tried using with app.app_context for each of the commands, but it only responds with a string version of the command, even if the command includes print statements, it doesn't even print an error. I may have to abandon this for a different tutorial. But so far it has has been great, and some of the stuff afterwards seems like it works to. just can't get the database part to work.
ОтветитьWould love to see an update version of this series. Or maybe FastAPI instead of Flask? I think the two are pretty similar.
Ответитьhey all!
as long as "The relationship.backref keyword should be considered legacy, and use of
relationship.back_populates with explicit relationship() constructs should be preferred. "
that's what I changed in models:
class User(db.Model):
# changed posts line:
posts = db.relationship('Post', back_populates='author')
class Post(db.Model):
# added line
author = db.relationship('User', back_populates='posts')
to see in Terminal those relationship attributes:
app.app_context().push()
u = User.query.filter_by(id=1).first()
u.posts
all_posts = Post.query.all()
all_posts[0].author
Hi all, found problem with creating DB. Im working in pycharm and when i type in terminal "from project import app, db",i get error "The 'from' keyword is not supported in this version of the language.". How i can fix it ?
Ответитьthnx buddy for recording such videos!
ОтветитьThank you so much these amazing explanations.
ОтветитьI'm facing this error "sqlalchemy.exc.InvalidRequestError: One or more mappers failed to initialize - can't proceed with initialization of other mappers." while trying to create user_1
please help.
thank you very much for your tutorial. its excelent.
Ответитьi don't have the coloring in vscode. for example db.Column(...) the function Column seen as white. But in Corey's screen its orange. How can i do that? :)
Ответитьgetting error like user_id column is not present in post table
ОтветитьHey All: As of version SQLAlchemy 3.0 to create your db file you will need to run some commands like this in the shell :
from project import app, db
app.app_context().push()
db.create_all()
Then the .db file is created in a folder called "Instance" in your project.
Hope this helps some one
How were you able to run those commands to create items in the database, without the application context issues? I know this is old, so maybe that is the answer, but still I was not able to do any of those commands without "with app.app_context()", and even then I still could not seem to add anything to the db.
Regardless, I really appreciate your series here, overall very helpful.
I have the same error @Othmane describes below and in my terminal, once I write the command my terminal tells me that 'from is not a recognized as an internal or external command'
ОтветитьHi team,
I'm wondering if anyone has come across this issue yet. I've tried to run 'from flaskblog import db' command, which returns some objections and this error message
"sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:sqllite"
Has anyone come across this before and if so, please can you share how you resolved the issue.
This video really helped me a lot, everything is clear now tysm Corey !
ОтветитьI am unable to do db.create_all()
ОтветитьDoes anyone had this error, using the python command at first, when typing db.create_all()?
[...]
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.
Hey probably a really bad nuub question but working with the db and getting some errors any thoughts in this ?
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.
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.
I got this with the db.session.add()
Before that, i added the:
```
with app.app_context():
db.create_all()
```
For anyone confused why (User.query.all()) is not returning any values, try this:
with app.app_context():
db.session.add(user_1)
db.session.add(user_2)
db.session.commit()
User.query.all()
For anyone who is facing the error of 'outside application context', try this :
- in your terminal: from <your_app> import app, db
- with app.app_context():
db.create_all()
Note: You can use this also when you will want to add data to the database. GoodLuck!
When attempting to create the database with db.create_all() this error comes up
RuntimeError: Working outside of application context.
How do I fix this?
I am getting this error while creating db model in 4th module. Any help please
sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:sqllite
It is showing an error out of application context. Would you please solve it?
ОтветитьLove this guy !
ОтветитьI'm getting this error, when I try to run db.create_all() in terminal:
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.
db.create_all() did not work for me, it shows this
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.
what should I do?
spending 3 hours to find solution to err : works outside of application context :)
Ответить!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!HELP NEEDED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
I cannot create database element using create_all() function in python terminal
It gives an error of Working outside of application context.
Please help anyone if you have resolved this issue.
Thank you.
thanks Corey, this is even better than paid courses !
Is there a way to create stored procedures and triggers in a OOP way with SQLAlchemy the way you did with models ?
I am getting an error when I try to db.create_all(). The error is: "RuntimeError: Working outside of application context". This even happens when I try to run the source code. Any idea why?
Ответитьfor anyone whose having an issue with db.create_all(), use the following commands after watching the next video.
(env) C:.\..\..\flask app\Flask_blog>set FLASK_APP=run
(env) C:.\..\..\flask app\Flask_blog>flask shell
>>> from flaskblog import db
>>> from flaskblog.models import User, Post
>>>db.create_all()
Anyone know how to fix the runtime error "Working outside of application context" when trying to run db.create_all()? please pm me <3
ОтветитьIf anyone got a 'working outside of application context' error when running db.create_all() ?
ОтветитьHey, I have some problems with my python program.
I already have a database in MySQL and don't know how to connect it with almost the same WTForms you used. Can you explain how to connect the WTForms to an already existing database in MySQL?
In the User class wthout using a constructor (__init__(self):) how can username,email etc became class variables
ОтветитьWhich color theme are you using sir?
ОтветитьIf someday I will decide to move such project online to some server, should I treat database something differently or I can keep that site.db file in the root folder of a project and connect to that database as shown here?
ОтветитьWhenever I try to access the user_id from the post, I get None. Could anyone please help me with this?
ОтветитьGreat Flask tutorials, thank you! Can I ask why use a SQLAlchemy db for dev and a PostgreSQL db for prod?
ОтветитьCould anyone explain what I would need to do differently if I wanted to use PostgreSQL? Is it a simple case of changing the URI in the configuration?
Ответить