Forums

Table doesn't exist with Sqlite3

The code works fine when I run it locally on my computer. However, when I uploaded the files to pythonanywhere it suddenly fails. I downloaded the database file and the table does indeed exist.

Here is the error message:

/usr/local/lib/python3.4/dist-packages/flask/app.py", line 1544, in handle_user_exception#012    reraise(exc_type, exc_value, tb)#012  File "/usr/local/lib/python3.4/dist-packages/flask/_compat.py", line 33, in reraise#012    raise value#012  File "/usr/local/lib/python3.4/dist-packages/flask/app.py", line 1639, in full_dispatch_request#012    rv = self.dispatch_request()#012  File "/usr/local/lib/python3.4/dist-packages/flask/app.py", line 1625, in dispatch_request#012    return self.view_functions[rule.endpoint](**req.view_args)#012  File "/home/GatesWang/mysite/flask_app.py", line 63, in find#012    return get_courses(req_nums)#012  File "/home/GatesWang/mysite/find_core_class.py", line 54, in get_courses#012    courses = c.execute(sql)#012sqlite3.OperationalError: no such table: requirement1
2018-07-29 06:54:05,136: [2018-07-29 06:54:05,133] ERROR in app: Exception on /find [POST]
2018-07-29 06:54:05,136: Traceback (most recent call last):
2018-07-29 06:54:05,136:   File "/usr/local/lib/python3.4/dist-packages/flask/app.py", line 1988, in wsgi_app
2018-07-29 06:54:05,136:     response = self.full_dispatch_request()
2018-07-29 06:54:05,136:   File "/usr/local/lib/python3.4/dist-packages/flask/app.py", line 1641, in full_dispatch_request
2018-07-29 06:54:05,137:     rv = self.handle_user_exception(e)
2018-07-29 06:54:05,137:   File "/usr/local/lib/python3.4/dist-packages/flask/app.py", line 1544, in handle_user_exception
2018-07-29 06:54:05,137:     reraise(exc_type, exc_value, tb)
2018-07-29 06:54:05,137:   File "/usr/local/lib/python3.4/dist-packages/flask/_compat.py", line 33, in reraise
2018-07-29 06:54:05,137:     raise value
2018-07-29 06:54:05,137:   File "/usr/local/lib/python3.4/dist-packages/flask/app.py", line 1639, in full_dispatch_request
2018-07-29 06:54:05,137:     rv = self.dispatch_request()
2018-07-29 06:54:05,137:   File "/usr/local/lib/python3.4/dist-packages/flask/app.py", line 1625, in dispatch_request
2018-07-29 06:54:05,137:     return self.view_functions[rule.endpoint](**req.view_args)
2018-07-29 06:54:05,137:   File "/home/GatesWang/mysite/flask_app.py", line 63, in find
2018-07-29 06:54:05,137:     return get_courses(req_nums)
2018-07-29 06:54:05,137:   File "/home/GatesWang/mysite/find_core_class.py", line 54, in get_courses
2018-07-29 06:54:05,137:     courses = c.execute(sql)
2018-07-29 06:54:05,138: sqlite3.OperationalError: no such table: requirement1
2018-07-29 06:54:05,133: Exception on /find [POST]#012Traceback (most recent call last):#012  File "/usr/local/lib/python3.4/dist-packages/flask/app.py", line 1988, in wsgi_app#012    response = self.full_dispatch_request()#012  File "/usr/local/lib/python3.4/dist-packages/flask/app.py", line 1641, in full_dispatch_request#012    rv = self.handle_user_exception(e)#012  File "/usr/local/lib/python3.4/dist-packages/flask/app.py", line 1544, in handle_user_exception#012    reraise(exc_type, exc_value, tb)#012  File "/usr/local/lib/python3.4/dist-packages/flask/_compat.py", line 33, in reraise#012    raise value#012  File "/usr/local/lib/python3.4/dist-packages/flask/app.py", line 1639, in full_dispatch_request#012    rv = self.dispatch_request()#012  File "/usr/local/lib/python3.4/dist-packages/flask/app.py", line 1625, in dispatch_request#012    return self.view_functions[rule.endpoint](**req.view_args)#012  File "/home/GatesWang/mysite/flask_app.py", line 63, in find#012    return get_courses(req_nums)#012  File "/home/GatesWang/mysite/find_core_class.py", line 54, in get_courses#012    courses = c.execute(sql)#012sqlite3.OperationalError: no such table: requirement1

[edit by admin: formatting]

My guess is that you're not accessing the database you intend to. Are you using SQLite? If so, what code are you using to connect to it? If you just specify the database file using a relative path like mydbfile.db, then it will try to access it using relative to the working directory of your website's code, which might not be what you expect it to be. You should instead either use an absolute path, or use the __file__ magic variable to work out the directory where the running code is located, and navigate to it from there. Let me know if you need more details on how to do that.