I keep getting the below error regarding the RuntimeError: Working outside of application context. when i use db.create_all() on terminal Please could someone point out where i'm going wrong.
from flask import Flask , render_template,url_for
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime
app= Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db'
db = SQLAlchemy(app)
class Todo(db.Model):
id = db.Column(db.Integer,primary_key=True)
content = db.Column(db.String(200),nullable=False)
date_created = db.Column(db.DateTime,default=datetime.utcnow)
def __repr__(self):
return '<Task %r>' % self.id
@app.route('/')
def index():
return render_template('index.html')
if __name__ =="__main__":
app.run(debug=True)
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(). See the documentation for more information.