Comments (5)
For those of you who faced the database creation error, do the following:
from app import app, db
app.app_context().push()
db.create_all()
it should be created under instance directory after those commands.
from flaskintroduction.
def create_tables():
db.create_all()
just add this lines after class Todo(db.Model) , after runing the app once put them as comment this worked for me
from flaskintroduction.
you can add
if__name__ == '__main__':
#app.run starts the app and contains variables and configures the app to run on localhost ("host=0.0.0.0"), the port (you can use a different one than 80) and sets it in debug mode ("debug=True")
app.run(host='0.0.0.0', port=80, debug=True)
with app.app_context():
db.create_all()
Now try to run direct app.py file
from flaskintroduction.
Is your virtual environment active in the terminal you start the REPL in? The error hints that you're attempting to execute code outside of its working context which sounds like an environment issue to me
from flaskintroduction.
call manually in the flask shell , this is because I think in Flask-SQLAlchemy to access the DB db.engine and db.session requires an active Flask app context , when you run the CLI command a context will be pushed automatically.
flask shell,
db.create_all()
from flaskintroduction.
Related Issues (5)
- Encountered an application error when deployed on Heroku using python 3.10.4 HOT 1
- Track sheet
- Attribute missing in the example HOT 6
- Every time I press "Add Task", it takes me to the "there was an issue adding your task" page, however, after returning back to the homepage, I can see that the task was successfully inserted. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flaskintroduction.