File tree Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -33,11 +33,17 @@ Because there might be more than one application created.
33
33
34
34
So how does :class: `SQLAlchemy ` come to know about your application?
35
35
You will have to setup an application context. If you are working inside
36
- a Flask view function, that automatically happens. However if you are
37
- working inside the interactive shell, you will have to do that yourself
38
- (see `Creating an Application Context
36
+ a Flask view function or a CLI command , that automatically happens. However,
37
+ if you are working inside the interactive shell, you will have to do that
38
+ yourself (see `Creating an Application Context
39
39
<http://flask.pocoo.org/docs/appcontext/#creating-an-application-context> `_).
40
40
41
+ If you try to perform database operations outside an application context, you
42
+ will see the following error:
43
+
44
+ No application found. Either work inside a view function or push an
45
+ application context.
46
+
41
47
In a nutshell, do something like this:
42
48
43
49
>>> from yourapp import create_app
Original file line number Diff line number Diff line change @@ -897,7 +897,8 @@ def get_app(self, reference_app=None):
897
897
898
898
raise RuntimeError (
899
899
'No application found. Either work inside a view function or push'
900
- ' an application context.'
900
+ ' an application context. See'
901
+ ' http://flask-sqlalchemy.pocoo.org/contexts/.'
901
902
)
902
903
903
904
def get_tables_for_bind (self , bind = None ):
You can’t perform that action at this time.
0 commit comments