diff --git a/example/app.py b/example/app.py index 77c688e..cd35b9e 100644 --- a/example/app.py +++ b/example/app.py @@ -28,11 +28,6 @@ class ExampleModel(db.Model): value = db.Column(db.String(100), primary_key=True) -@app.before_first_request -def setup(): - db.create_all() - - @app.route('/') def index(): app.logger.info("Hello there") @@ -45,3 +40,7 @@ def redirect_example(): response = redirect(url_for('index')) response.set_cookie('test_cookie', '1') return response + + +with app.app_context(): + db.create_all() diff --git a/test/basic_app.py b/test/basic_app.py index 6ec1ddd..689d14a 100644 --- a/test/basic_app.py +++ b/test/basic_app.py @@ -6,7 +6,7 @@ app = Flask('basic_app') app.config['SECRET_KEY'] = 'abc123' app.config['SQLALCHEMY_RECORD_QUERIES'] = True -app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db' +app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:' # This is no longer needed for Flask-SQLAlchemy 3.0+, if you're using 2.X you'll want to define this: # app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False @@ -23,12 +23,11 @@ class Foo(db.Model): id = db.Column(db.Integer, primary_key=True) -@app.before_first_request -def setup(): - db.create_all() - - @app.route('/') def index(): Foo.query.filter_by(id=1).all() return render_template('basic_app.html') + + +with app.app_context(): + db.create_all()