Skip to content

Commit 859216e

Browse files
committed
add app context error message to docs
add link to docs to error message fixes pallets-eco#553
1 parent 0ed2250 commit 859216e

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

docs/contexts.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,17 @@ Because there might be more than one application created.
3333

3434
So how does :class:`SQLAlchemy` come to know about your application?
3535
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
3939
<http://flask.pocoo.org/docs/appcontext/#creating-an-application-context>`_).
4040

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+
4147
In a nutshell, do something like this:
4248

4349
>>> from yourapp import create_app

flask_sqlalchemy/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,8 @@ def get_app(self, reference_app=None):
897897

898898
raise RuntimeError(
899899
'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/.'
901902
)
902903

903904
def get_tables_for_bind(self, bind=None):

0 commit comments

Comments
 (0)