File tree Expand file tree Collapse file tree 2 files changed +9
-11
lines changed Expand file tree Collapse file tree 2 files changed +9
-11
lines changed Original file line number Diff line number Diff line change @@ -28,11 +28,6 @@ class ExampleModel(db.Model):
28
28
value = db .Column (db .String (100 ), primary_key = True )
29
29
30
30
31
- @app .before_first_request
32
- def setup ():
33
- db .create_all ()
34
-
35
-
36
31
@app .route ('/' )
37
32
def index ():
38
33
app .logger .info ("Hello there" )
@@ -45,3 +40,7 @@ def redirect_example():
45
40
response = redirect (url_for ('index' ))
46
41
response .set_cookie ('test_cookie' , '1' )
47
42
return response
43
+
44
+
45
+ with app .app_context ():
46
+ db .create_all ()
Original file line number Diff line number Diff line change 6
6
app = Flask ('basic_app' )
7
7
app .config ['SECRET_KEY' ] = 'abc123'
8
8
app .config ['SQLALCHEMY_RECORD_QUERIES' ] = True
9
- app .config ['SQLALCHEMY_DATABASE_URI' ] = 'sqlite:////tmp/test.db '
9
+ app .config ['SQLALCHEMY_DATABASE_URI' ] = 'sqlite:///:memory: '
10
10
# This is no longer needed for Flask-SQLAlchemy 3.0+, if you're using 2.X you'll want to define this:
11
11
# app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
12
12
@@ -23,12 +23,11 @@ class Foo(db.Model):
23
23
id = db .Column (db .Integer , primary_key = True )
24
24
25
25
26
- @app .before_first_request
27
- def setup ():
28
- db .create_all ()
29
-
30
-
31
26
@app .route ('/' )
32
27
def index ():
33
28
Foo .query .filter_by (id = 1 ).all ()
34
29
return render_template ('basic_app.html' )
30
+
31
+
32
+ with app .app_context ():
33
+ db .create_all ()
You can’t perform that action at this time.
0 commit comments