GithubHelp home page GithubHelp logo

Comments (5)

FaustWarrior avatar FaustWarrior commented on May 18, 2024 2

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.

linaMallek avatar linaMallek commented on May 18, 2024 1

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.

ParthChodvadiya1 avatar ParthChodvadiya1 commented on May 18, 2024

@fthobe

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.

jakerieger avatar jakerieger commented on May 18, 2024

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.

YohanesGetinet1 avatar YohanesGetinet1 commented on May 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.