Forums

sqlalchemy.exc.OperationalError: (OperationalError) no such table

Hello!

I'm new to PythonAnywhere, and I'm trying to deploy a project that I completed a few months ago and had working locally.

I'm getting an error now relating to my database: it's a SQLite DB and I'm using sqlAlchemy to query and write to it.

Here's the error: sqlalchemy.exc.OperationalError: (OperationalError) no such table Time_habits...

I went ahead and downloaded the db from github to my computer and checked, and there is indeed a table called Time_habits, as well as a second called Money_habits in the database I cloned from my githhub repo. SQLAlchemy is installed in my venv.

I'm not sure if it can't find that table, if there's some issue with the WSGI file, or if there's some other issue. Any suggestions?

This is the full error I'm seeing in the log:

2015-09-17 20:35:45,678 : File "/bin/user_wsgi_wrapper.py", line 134, in call 2015-09-17 20:35:45,678 : self.error_log_file.logger.exception("Error running WSGI application") 2015-09-17 20:35:45,678 : File "/usr/lib/python2.7/logging/init.py", line 1185, in exception 2015-09-17 20:35:45,678 : self.error(msg, args, kwargs) 2015-09-17 20:35:45,678 : File "/usr/lib/python2.7/logging/init.py", line 1178, in error 2015-09-17 20:35:45,679 : self._log(ERROR, msg, args, *kwargs) 2015-09-17 20:35:45,679 : File "/usr/lib/python2.7/logging/init.py", line 1270, in _log 2015-09-17 20:35:45,679 : record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra) 2015-09-17 20:35:45,679 : File "/usr/lib/python2.7/logging/init.py", line 1244, in makeRecord 2015-09-17 20:35:45,679 : rv = LogRecord(name, level, fn, lno, msg, args, exc_info, func) 2015-09-17 20:35:45,679 : File "/usr/lib/python2.7/logging/init.py", line 284, in init 2015-09-17 20:35:45,680 : self.threadName = threading.current_thread().name 2015-09-17 20:35:45,680 : File "/usr/lib/python2.7/threading.py", line 1160, in currentThread 2015-09-17 20:35:45,680 : return _active[_get_ident()] 2015-09-17 20:35:45,680 : File "/bin/user_wsgi_wrapper.py", line 126, in call 2015-09-17 20:35:45,680 : app_iterator = self.app(environ, start_response) 2015-09-17 20:35:45,680 : File "/bin/user_wsgi_wrapper.py", line 140, in import_error_application 2015-09-17 20:35:45,680 : raise e 2015-09-17 20:35:45,680 :sqlalchemy.exc.OperationalError: (OperationalError) no such table: Time_habits u'SELECT "Time_habits".id AS "Time_habits_id", "Time_habits".hhld_id AS "Time_habits_hhld_id", "Time_habits".person_id AS "Time_habits_person_id", "Time_habits".sex AS "Time_habits_sex", "Time_habits".education AS "Time_habits_education", "Time_habits".age_range AS "Time_habits_age_range", "Time_habits".region AS "Time_habits_region", "Time_habits".income AS "Time_habits_income", "Time_habits".exercise_habit_timemin AS "Time_habits_exercise_habit_timemin", "Time_habits".work_habit_timemin AS "Time_habits_work_habit_timemin", "Time_habits".sleep_habit_timemin AS "Time_habits_sleep_habit_timemin" \nFROM "Time_habits"' ()

Here is a link to the github repo: https://github.com/eleanorstrib/habitually

Let me know if you need any additional information, and thanks!

The most likely problem is that your webapp is not reading the database you think it's reading. The easiest way to fix it is to use the full path to your database file and not a relative path.

Thanks glenn, that did the trick - for anyone else finding this, it took me a couple of tries and some Googling because I didn't know three slashes indicate a relative path while four slashes indicate an absolute path when you create your engine.

For example, this didn't work: "sqlite:///home/<username>/<app_name>/<db_name>.db"

But this did: "sqlite:////home/<username>/<app_name>/<db_name>.db"

Thanks for posting that! The four-slashes-for-root thing is pretty weird...