Ahmed Basha
Ahmed Basha

Reputation: 51

django.db.utils.OperationalError: no such table

I'm upgrading a Django project from 1.8 to 1.9, I deleted the database file and all cache files, then I tried to run

python manage.py migrate

or

python manage.py migrate --run-syncdb

but always raise this error django.db.utils.OperationalError: no such table:

here is the full traceback

Traceback (most recent call last):


File "manage.py", line 25, in <module>
    execute_from_command_line(sys.argv)
  File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
    utility.execute()
  File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 342, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/core/management/base.py", line 398, in execute
    self.check()
  File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/core/management/base.py", line 426, in check
    include_deployment_checks=include_deployment_checks,
  File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/core/checks/registry.py", line 75, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/core/checks/urls.py", line 10, in check_url_config
    return check_resolver(resolver)
  File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/core/checks/urls.py", line 19, in check_resolver
    for pattern in resolver.url_patterns:
  File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/utils/functional.py", line 33, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 417, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/utils/functional.py", line 33, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 410, in urlconf_module
    return import_module(self.urlconf_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/basha/UpgradeMloss/mloss/urls.py", line 30, in <module>
    (r'^community/', include('community.urls')),
  File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/conf/urls/__init__.py", line 52, in include
    urlconf_module = import_module(urlconf_module)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/basha/UpgradeMloss/mloss/community/urls.py", line 32, in <module>
    'extra_context' : get_latest_news()
  File "/home/basha/UpgradeMloss/mloss/community/summary.py", line 68, in get_latest_news
    latest_posts = get_latest_posts()
  File "/home/basha/UpgradeMloss/mloss/community/summary.py", line 32, in get_latest_posts
    for forum in all_forums:
  File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/db/models/query.py", line 258, in __iter__
    self._fetch_all()
  File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/db/models/query.py", line 1074, in _fetch_all
    self._result_cache = list(self.iterator())
  File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/db/models/query.py", line 52, in __iter__
    results = compiler.execute_sql()
  File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 852, in execute_sql
    cursor.execute(sql, params)
  File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/db/utils.py", line 95, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 323, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: community_forum

it works fine on django1.8 without any error! Are there any edits or updates should I make in Settings.py?

Upvotes: 0

Views: 6433

Answers (2)

AnonymousUser
AnonymousUser

Reputation: 786

After python3 manage.py makemigrations or python manage.py makemigrations

I did python3 manage.py migrate --fake or python manage.py migrate --fake.

It somehow worked. I did this fake migration after that I had commented out a ForeignKey, the model to the ForeignKey and the model in admin.py. I then went and looked in the admin, and the ForeignKey model was gone. So I did add that ForeignKey, model and admin.site.register back and did a real migration, the error was gone.

Upvotes: 0

Daniel Roseman
Daniel Roseman

Reputation: 600059

This question isn't related to your upgrade. You have a query inside your urls.py, where you do 'extra_context' : get_latest_news(). That executes as soon as the URLs are imported; so the migrations can never have a chance to run.

Note that as well as blocking the migrations, this code would give you out-of-date results, for the same reason: it is executed on import, not when the request is run. Remove that query and move it into the view itself.

Nevertheless, you really shouldn't have deleted the database, or the migration files.

Upvotes: 4

Related Questions