OperatorError no such table

I am trying to run my django project on PythonAnywhere and keep getting the error

"OperationalError at /
no such table: analysis_predictions"

when I go to my site. I am using sqlite3 and python 2.7. It seems like this is a common error and I have followed a bunch of instructions to try to fix it including adding the full file path to my database settings. When I try to run python migrate in the pythonanywhere bash console I get the error "OperationalError unable to open database file".

       'default': {
       'ENGINE': 'django.db.backends.sqlite3',


I also had the name as 'NAME': os.path.join(BASE_DIR, 'db.sqlite3') and it still didn't work.

/Users/Dahlia/learning_python/scifairserver/db.sqlite3 is not a path that exists on PythonAnywhere. Use the BASE_DIR code and ensure that you run the migrate and reload your web app after you've made the change. It's also possible that you have a broken sqlite file, so perhaps you could also try removing it to ensure that you're starting clean.

I've removed it and then pulled everything down again from github-- no luck. I've also tried again with the BASE_DIR code and gotten the same error. Should I try replacing the actual db.sqlite3 file on my computer? I can't run python makemigrations in my virtual environment without getting the table doesn't exist error.

Just to clarify- did you try to move a db.sqlite3 from say a windows machine onto PythonAnywhere? In that case it wouldn't work (because of windows vs linux).

I would try to get the migrate to work on PythonAnywhere. It should work as long as you have the database path setup correctly.

No- I have a mac and am pulling all my files from github. I can migrate the databases on my mac but not on PythonAnywhere.

What's the error that you are seeing when you try to migrate?

$ python makemigrations ... File "/home/dahlia/scifair/local/lib/python2.7/site-packages/django/db/backends/sqlite3/", line 337, in execute return Database.Cursor.execute(self, query, params) django.db.utils.OperationalError: no such table: analysis_predictions

I would try to get migrate working. What's the error for that? Not makemigrations.

I get the same error regardless :(

$python migrate
File "/home/dahlia/scifair/local/lib/python2.7/site-packages/django/db/backends/", line 64, in execute
return self.cursor.execute(sql, params)
File "/home/dahlia/scifair/local/lib/python2.7/site-packages/django/db/backends/sqlite3/", line 337, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: analysis_predictions

That's weird. What happens if you wipe the sql file and then run migrate again?

This gives the same error as before:

$rm db.sqlite3
$python migrate

Could the issue be with the file on my computer? I don't really know how database files work.

So that sounds like the migrations that you had previously made is broken. I would say delete all your app/migrations files, and then do a make migrations to regenerate them and then migrate

I have all of my models in one app, so I deleted all the migrations in the migrations folder in that app and got the same error:

django.db.utils.OperationalError: no such table: analysis_predictions

Analysis is the name of my app, and predictions is a model within the app, in case that needed to be clarified. I have two other models in the models file for the app, but for some reason this is the only one that's giving the error.

I removed all mentions of the predictions database in my files and then pushed everything to github to see if I could get the site to run. The migration completes successfully but on the web page I still get the error "no such table" but with either or the other two databases instead. I can get into my admin page, but if I try to edit databases from there I am brought to the same error page saying the tables don't exist.

Also, I tried to migrate analysis back to zero, which didn't work:

(scifair) 21:36 ~/project (master)$ python migrate analysis zero
CommandError: App 'analysis' does not have migrations.

but this may be because I'm running a newer version of django?

ooooh there are multiple databases? I would also say make sure you are running the migration on the correct database, and that your django code is actually accessing the correct databases then.

How would I do that? My code runs fine on the test server and accesses the databases with no problems. Would it work if I put each database in a separate file? If I try to migrate, pythonanywhere says there are no migrations to be made because if I try to do makemigrations it says there are no changes to be made.

Can we have permission to take a look at your files?

Here's the link to my github repository:

Are you using a virtualenv? Is it activated when you're running the migrations?


You have a piece of code in that tries to delete from the predictions table. Since it's run at import time, it's happening before the migrate command gets to run and create the table.

Thanks for the advice-- that stopped the error for the predictions database. Now when I try to migrate I get the same error but for the timeseries database-- it traces back to where I put all the values from the timeseries database into a pandas dataframe (line 24). I had previously deleted all my migrations files on pythonanywhere- do I need to add them back?

Yes, you need to keep the migration files around. If restoring them doesn't help, could you copy/paste the whole traceback here?

weird- I got the migration files back but I still get the "no such table" error.

Still for the analysis_predictions table?

no- analysis_timeseries

OK, and as I understand it you're getting this error when you run the migration. Could you copy/paste the complete traceback? And also, if you run a dbshell, what do you get if you run SELECT name FROM sqlite_master WHERE type='table'?

entire traceback for

   python migrate
   Traceback (most recent call last):
   File "", line 22, in <module>
   File "/home/dahlia/scifair/local/lib/python2.7/site-packages/django/core/management/", line 367, in execute_from_command_line
   File "/home/dahlia/scifair/local/lib/python2.7/site-packages/django/core/management/", line 359, in execute
   File "/home/dahlia/scifair/local/lib/python2.7/site-packages/django/core/management/", line 294, in run_from_argv
   self.execute(*args, **cmd_options)
   File "/home/dahlia/scifair/local/lib/python2.7/site-packages/django/core/management/", line 342, in execute
   File "/home/dahlia/scifair/local/lib/python2.7/site-packages/django/core/management/", line 374, in check
  File "/home/dahlia/scifair/local/lib/python2.7/site-packages/django/core/management/commands/", line 62, in _run_checks
  issues.extend(super(Command, self)._run_checks(**kwargs))
  File "/home/dahlia/scifair/local/lib/python2.7/site-packages/django/core/management/", line 361, in _run_checks
  return checks.run_checks(**kwargs)
  File "/home/dahlia/scifair/local/lib/python2.7/site-packages/django/core/checks/", line 81, in run_checks
  new_errors = check(app_configs=app_configs)
  File "/home/dahlia/scifair/local/lib/python2.7/site-packages/django/core/checks/", line 14, in check_url_config
  return check_resolver(resolver)
  File "/home/dahlia/scifair/local/lib/python2.7/site-packages/django/core/checks/", line 24, in check_resolver
  for pattern in resolver.url_patterns:
  File "/home/dahlia/scifair/local/lib/python2.7/site-packages/django/utils/", line 35, in __get__
  res = instance.__dict__[] = self.func(instance)
  File "/home/dahlia/scifair/local/lib/python2.7/site-packages/django/urls/", line 313, in url_patterns
  patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/home/dahlia/scifair/local/lib/python2.7/site-packages/django/utils/", line 35, in __get__
  res = instance.__dict__[] = self.func(instance)
  File "/home/dahlia/scifair/local/lib/python2.7/site-packages/django/urls/", line 306, in urlconf_module
  return import_module(self.urlconf_name)
  File "/usr/lib/python2.7/importlib/", line 37, in import_module
  File "/home/dahlia/project/scifairserver/", line 24, in <module>
   url(r'^forecasts/', include('forecasts.urls')),
  File "/home/dahlia/scifair/local/lib/python2.7/site-packages/django/conf/urls/", line 50, in include
   urlconf_module = import_module(urlconf_module)
  File "/usr/lib/python2.7/importlib/", line 37, in import_module
  File "/home/dahlia/project/forecasts/", line 2, in <module>
  from . import views
  File "/home/dahlia/project/forecasts/", line 11, in <module>
  from analysis import TIMESERIES
  File "/home/dahlia/project/analysis/", line 24, in <module>
  dataframe = pd.DataFrame(list(timeseries.objects.all().values()))
  File "/home/dahlia/scifair/local/lib/python2.7/site-packages/django/db/models/", line 256, in __iter__
  File "/home/dahlia/scifair/local/lib/python2.7/site-packages/django/db/models/", line 1087, in _fetch_all
  self._result_cache = list(self.iterator())
  File "/home/dahlia/scifair/local/lib/python2.7/site-packages/django/db/models/", line 109, in __iter__
  for row in compiler.results_iter():
  File "/home/dahlia/scifair/local/lib/python2.7/site-packages/django/db/models/sql/", line 789, in results_iter
  results = self.execute_sql(MULTI)
  File "/home/dahlia/scifair/local/lib/python2.7/site-packages/django/db/models/sql/", line 835, in   execute_sql
  cursor.execute(sql, params)
  File "/home/dahlia/scifair/local/lib/python2.7/site-packages/django/db/backends/", line 79, in execute
  return super(CursorDebugWrapper, self).execute(sql, params)
  File "/home/dahlia/scifair/local/lib/python2.7/site-packages/django/db/backends/", line 64, in execute
  return self.cursor.execute(sql, params)
  File "/home/dahlia/scifair/local/lib/python2.7/site-packages/django/db/", line 94, in __exit__
  six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/home/dahlia/scifair/local/lib/python2.7/site-packages/django/db/backends/", line 64, in execute
  return self.cursor.execute(sql, params)
  File "/home/dahlia/scifair/local/lib/python2.7/site-packages/django/db/backends/sqlite3/", line 337, in execute
  return Database.Cursor.execute(self, query, params)
 django.db.utils.OperationalError: no such table: analysis_timeseries

if I run

SELECT name FROM sqlite_master WHERE type='table';

in dbshell, I get nothing back. I haven't used dbshell very much so I'm not sure if I typed it in wrong or something?

you do have the initial migrations for analysis_timeseries right?

I have an file in migrations folder, if that's what you're asking? I haven't been able to migrate or makemigrations successfully within the pythonanywhere terminal though.

hmm what if you try a more fine-grained migrate

eg: python migrate app1

and go through your different apps to see which one is broken.

There is apparently also a --run-syncdb flag that you can try just to see what happens. (presumably then it would create all the tables without applying the migrations)

Hi all,

I am having a similar issue. I'm pretty new to Django fyi.

New Django App. Using Django 2.0.3 in my virtual environment. cloned the app from github, (working on my mac), made migrations --> tried to run it on Python Anywhere.

On accessing the page: OperationalError at /GR/ no such table: GR_intervention

I tried to change the settings to ensure the db.sqlite3 was being accessed, changed the path also but no dice. Currently it reads in Settings:

'default': {
    'ENGINE': 'django.db.backends.sqlite3',
    'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),

I tried deleting db.sqlite3 and reloading as well as deleting and re-performing migrations. No errors there, but still not working.

Any help would be much appreciated! Thanks

I see you posted this one in a different topic too, so will respond there.