Forums

Flask db.create_all() error

I got into the python bash and when i type db.create_(), the error says

db.create_all() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python2.7/dist-packages/flask_sqlalchemy/init.py", line 1033, in create_all self._execute_for_all_tables(app, bind, 'create_all') File "/usr/local/lib/python2.7/dist-packages/flask_sqlalchemy/init.py", line 1010, in _execute_for_all_t ables app = self.get_app(app) File "/usr/local/lib/python2.7/dist-packages/flask_sqlalchemy/init.py", line 982, in get_app 'No application found. Either work inside a view function or push' RuntimeError: No application found. Either work inside a view function or push an application context. See htt p://flask-sqlalchemy.pocoo.org/contexts/.

Looking at this...

File "/usr/local/lib/python2.7/dist-packages/flask_sqlalchemy/init.py", line 1010, in _execute_for_all_tables app...

It looks like you are running Python 2.7, which is most likely the cause. Personally, I recommend using a virtualenv (PA help page).

There are multiple versions of Python installed; if you run "python3.8", you'll get Python 3.8, if you run "python3.7", you'll get 3.7, and so on. They all have their own associated versions of pip installed, eg. "pip3.8". The commands "python" and "pip" are aliased to "python2.7" and "pip2.7" respectively because unfortunately, that's what Ubuntu requires to run.