django.db.utils.OperationalError:没有这样的表

时间:2018-09-11 13:51:21

标签: python django python-2.7

我要将Django项目从1.8升级到1.9, 我删除了数据库文件和所有缓存文件,然后尝试运行

python manage.py migrate

python manage.py migrate --run-syncdb

但总是会出现此错误 django.db.utils.OperationalError:没有这样的表:

这是完整的追溯

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

它在 django1.8 上正常运行,没有任何错误! 我应该在 Settings.py 中进行任何编辑或更新吗?

1 个答案:

答案 0 :(得分:1)

此问题与您的升级无关。您在urls.py中有一个查询,您在其中进行'extra_context' : get_latest_news()。 URL导入后立即执行;因此迁移永远不会有机会运行。

请注意,除了阻止迁移外,此代码还会为您提供过时的结果,原因相同:在导入时执行,而不是在运行请求时执行。删除该查询并将其移至视图本身。

尽管如此,您实际上不应该删除数据库或迁移文件。