-2
>>> from app import db
>>> db.create_all()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\kinut\AppData\Local\Programs\Python\Python311\Lib\site-packages\flask_sqlalchemy\extension.py", line 868, in create_all
    self._call_for_binds(bind_key, "create_all")
  File "C:\Users\kinut\AppData\Local\Programs\Python\Python311\Lib\site-packages\flask_sqlalchemy\extension.py", line 839, in _call_for_binds
    engine = self.engines[key]
             ^^^^^^^^^^^^
  File "C:\Users\kinut\AppData\Local\Programs\Python\Python311\Lib\site-packages\flask_sqlalchemy\extension.py", line 628, in engines
    app = current_app._get_current_object()  # type: ignore[attr-defined]
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kinut\AppData\Local\Programs\Python\Python311\Lib\site-packages\werkzeug\local.py", line 513, in _get_current_object
    raise RuntimeError(unbound_message) from None
RuntimeError: Working outside of application context.

i ran into this error while trying to create an sqlite database

expected no return, just creation of the database

0

1 Answer 1

0
from mycode import app
from mycode import db
with app.app_context():
    db.create_all()
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.