switowski / modern-python-workshop

4 stars 0 forks source link

'SQLalchemy.exc.OperationalError: no such table: task' #1

Open JustinWG opened 3 years ago

JustinWG commented 3 years ago

127.0.0.1 - - [04/Sep/2020 09:23:27] "GET / HTTP/1.1" 500 - Error on request: Traceback (most recent call last): File "/Users/justingold/.pyenv/versions/3.8.5/envs/ToDoList/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context self.dialect.do_execute( File "/Users/justingold/.pyenv/versions/3.8.5/envs/ToDoList/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 593, in do_execute cursor.execute(statement, parameters) sqlite3.OperationalError: no such table: task

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/Users/justingold/.pyenv/versions/3.8.5/envs/ToDoList/lib/python3.8/site-packages/werkzeug/serving.py", line 323, in run_wsgi execute(self.server.app) File "/Users/justingold/.pyenv/versions/3.8.5/envs/ToDoList/lib/python3.8/site-packages/werkzeug/serving.py", line 312, in execute application_iter = app(environ, start_response) File "/Users/justingold/.pyenv/versions/3.8.5/envs/ToDoList/lib/python3.8/site-packages/flask/app.py", line 2463, in call return self.wsgi_app(environ, start_response) File "/Users/justingold/.pyenv/versions/3.8.5/envs/ToDoList/lib/python3.8/site-packages/flask/app.py", line 2449, in wsgi_app response = self.handle_exception(e) File "/Users/justingold/.pyenv/versions/3.8.5/envs/ToDoList/lib/python3.8/site-packages/flask/app.py", line 1866, in handle_exception reraise(exc_type, exc_value, tb) File "/Users/justingold/.pyenv/versions/3.8.5/envs/ToDoList/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise raise value File "/Users/justingold/.pyenv/versions/3.8.5/envs/ToDoList/lib/python3.8/site-packages/flask/app.py", line 2446, in wsgi_app response = self.full_dispatch_request() File "/Users/justingold/.pyenv/versions/3.8.5/envs/ToDoList/lib/python3.8/site-packages/flask/app.py", line 1951, in full_dispatch_request rv = self.handle_user_exception(e) File "/Users/justingold/.pyenv/versions/3.8.5/envs/ToDoList/lib/python3.8/site-packages/flask/app.py", line 1820, in handle_user_exception reraise(exc_type, exc_value, tb) File "/Users/justingold/.pyenv/versions/3.8.5/envs/ToDoList/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise raise value File "/Users/justingold/.pyenv/versions/3.8.5/envs/ToDoList/lib/python3.8/site-packages/flask/app.py", line 1949, in full_dispatch_request rv = self.dispatch_request() File "/Users/justingold/.pyenv/versions/3.8.5/envs/ToDoList/lib/python3.8/site-packages/flask/app.py", line 1935, in dispatch_request return self.view_functionsrule.endpoint File "/Users/justingold/Development/ToDoList/todo/views.py", line 11, in tasks_list tasks = get_tasks() File "/Users/justingold/Development/ToDoList/todo/api.py", line 7, in get_tasks return Task.query.all() File "/Users/justingold/.pyenv/versions/3.8.5/envs/ToDoList/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3346, in all return list(self) File "/Users/justingold/.pyenv/versions/3.8.5/envs/ToDoList/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3508, in iter return self._execute_and_instances(context) File "/Users/justingold/.pyenv/versions/3.8.5/envs/ToDoList/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3533, in _execute_and_instances result = conn.execute(querycontext.statement, self._params) File "/Users/justingold/.pyenv/versions/3.8.5/envs/ToDoList/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1011, in execute return meth(self, multiparams, params) File "/Users/justingold/.pyenv/versions/3.8.5/envs/ToDoList/lib/python3.8/site-packages/sqlalchemy/sql/elements.py", line 298, in _execute_on_connection return connection._execute_clauseelement(self, multiparams, params) File "/Users/justingold/.pyenv/versions/3.8.5/envs/ToDoList/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1124, in _execute_clauseelement ret = self._execute_context( File "/Users/justingold/.pyenv/versions/3.8.5/envs/ToDoList/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1316, in _execute_context self._handle_dbapi_exception( File "/Users/justingold/.pyenv/versions/3.8.5/envs/ToDoList/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1510, in _handle_dbapiexception util.raise( File "/Users/justingold/.pyenv/versions/3.8.5/envs/ToDoList/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 182, in raise_ raise exception File "/Users/justingold/.pyenv/versions/3.8.5/envs/ToDoList/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context self.dialect.do_execute( File "/Users/justingold/.pyenv/versions/3.8.5/envs/ToDoList/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 593, in do_execute cursor.execute(statement, parameters) sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: task [SQL: SELECT task.id AS task_id, task.body AS task_body, task.done AS task_done FROM task]

I am trying to run the Flask app cookie-cutter (with scaffolding) out of the box. I am not sure how to fix this error; my best guess is the imports cause the 'tasks_list' view to run prior to db.create_all() and therefore it is trying to query an entirely empty database. But the imports/route is the same as the finished product, so I'd think that would work?

switowski commented 3 years ago

Hey Justin, sorry for the late reply.

I'm afraid that I can't replicate this problem. What I just did was:

And everything worked fine. Did you run it the same way or differently?

When you start the application, it should create the db file (todo.db inside the todo folder - in the same place where the api.py or models.py are). Can you check if it's there? Maybe your user doesn't have permission to create a new file?

And if the todo.db is there, try to delete it (it will be recreated next time you restart the server). Maybe it got corrupted somehow?