简体   繁体   English

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

[英]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我正在将一个 Django 项目从 1.8 升级到 1.9,我删除了数据库文件和所有缓存文件,然后我尝试运行

python manage.py migrate

or或者

python manage.py migrate --run-syncdb

but always raise this error django.db.utils.OperationalError: no such table:但总是引发此错误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!它在django1.8上运行良好,没有任何错误! Are there any edits or updates should I make in Settings.py ?我应该在Settings.py中进行任何编辑或更新吗?

This question isn't related to your upgrade. 这个问题与您的升级无关。 You have a query inside your urls.py, where you do 'extra_context' : get_latest_news() . 您在urls.py中有一个查询,在其中执行'extra_context' : get_latest_news() That executes as soon as the URLs are imported; URL导入后立即执行; 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. 但是,您实际上不应该删除数据库或迁移文件。

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

I did python3 manage.py migrate --fake or python manage.py migrate --fake .我做了python3 manage.py migrate --fakepython 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 .在我注释掉ForeignKey 、 ForeignKey 的 model 和 admin.py 中的model之后,我做了这个假迁移。 I then went and looked in the admin, and the ForeignKey model was gone.然后我去管理员那里看了看,外键 model不见了。 So I did add that ForeignKey , model and admin.site.register back and did a real migration, the error was gone.所以我确实添加了ForeignKey , model 和admin.site.register并进行了真正的迁移,错误消失了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 django.db.utils.OperationalError: 没有这样的表 Django 2 - django.db.utils.OperationalError: no such table Django 2 PythonAnywhere:django.db.utils.OperationalError:没有这样的表: - PythonAnywhere: django.db.utils.OperationalError: no such table: Django 2.2 - django.db.utils.OperationalError: 没有这样的表 - Django 2.2 - django.db.utils.OperationalError: no such table django.db.utils.OperationalError:没有这样的表:django_site - django.db.utils.OperationalError: no such table: django_site Django迁移django.db.utils.OperationalError:没有这样的表: - Django migrate django.db.utils.OperationalError: no such table: django.db.utils.OperationalError: 没有这样的表: polls_post - django.db.utils.OperationalError: no such table: polls_post Makemigrations 错误:django.db.utils.OperationalError:没有这样的表 - Makemigrations error : django.db.utils.OperationalError: no such table django.db.utils.OperationalError:没有这样的表:Homepage_generalsettings - django.db.utils.OperationalError: no such table: Homepage_generalsettings django.db.utils.OperationalError:SQLite3 数据库中没有这样的表 - django.db.utils.OperationalError: no such table in SQLite3 database django.db.utils.OperationalError:没有这样的表:theblog_category - django.db.utils.OperationalError: no such table: theblog_category
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM