gpt4 book ai didi

django - 无法在现有 Django 项目上从头开始恢复数据库

转载 作者:行者123 更新时间:2023-11-29 13:17:06 28 4
gpt4 key购买 nike

我有一个现有的 Django 1.10 应用程序,我想从头开始在本地创建一个新的数据库。

按照这些步骤

$ createdb -h localhost -p 5432 -U me -w my_db    # OK
$ ./manage.py migrate

我遇到了异常

Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/me/workspace/myproject-django/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/home/me/workspace/myproject-django/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 341, in execute
django.setup()
File "/home/me/workspace/myproject-django/venv/local/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/me/workspace/myproject-django/venv/local/lib/python2.7/site-packages/django/apps/registry.py", line 115, in populate
app_config.ready()
File "/home/me/workspace/myproject-django/venv/local/lib/python2.7/site-packages/django/contrib/admin/apps.py", line 23, in ready
self.module.autodiscover()
File "/home/me/workspace/myproject-django/venv/local/lib/python2.7/site-packages/django/contrib/admin/__init__.py", line 26, in autodiscover
autodiscover_modules('admin', register_to=site)
File "/home/me/workspace/myproject-django/venv/local/lib/python2.7/site-packages/django/utils/module_loading.py", line 50, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/me/workspace/myproject-django/customauth/admin.py", line 7, in <module>
from core.admin import ShopInline
File "/home/me/workspace/myproject-django/core/admin.py", line 242, in <module>
admin.site.register(Campaign, CampaignAdmin)
File "/home/me/workspace/myproject-django/venv/local/lib/python2.7/site-packages/django/contrib/admin/sites.py", line 108, in register
admin_obj = admin_class(model, self)
File "/home/me/workspace/myproject-django/core/admin.py", line 104, in __init__
last_task = TaskState.objects.filter(name='core.tasks.compute_metrics', state='SUCCESS').order_by('tstamp').last()
File "/home/me/workspace/myproject-django/venv/local/lib/python2.7/site-packages/django/db/models/query.py", line 565, in last
objects = list((self.reverse() if self.ordered else self.order_by('-pk'))[:1])
File "/home/me/workspace/myproject-django/venv/local/lib/python2.7/site-packages/django/db/models/query.py", line 256, in __iter__
self._fetch_all()
File "/home/me/workspace/myproject-django/venv/local/lib/python2.7/site-packages/django/db/models/query.py", line 1087, in _fetch_all
self._result_cache = list(self.iterator())
File "/home/me/workspace/myproject-django/venv/local/lib/python2.7/site-packages/django/db/models/query.py", line 54, in __iter__
results = compiler.execute_sql()
File "/home/me/workspace/myproject-django/venv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 835, in execute_sql
cursor.execute(sql, params)
File "/home/me/workspace/myproject-django/venv/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/home/me/workspace/myproject-django/venv/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/home/me/workspace/myproject-django/venv/local/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/me/workspace/myproject-django/venv/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "celery_monitor_taskstate" does not exist
LINE 1: ...ker_id", "celery_monitor_taskstate"."hidden" FROM "celery_mo...

这是我的 requirements.txt

的相关部分
celery==4.0.2
django-celery-beat==1.0.1
django-celery-monitor==1.1.0
django-celery-results==1.0.1

这是我的INSTALLED_APPS

INSTALLED_APPS = (
'modeltranslation',
...
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'django.contrib.postgres',
'django_countries',
'django_extensions',
'django.contrib.humanize',
'django_celery_results',
'django_celery_beat',
'django_celery_monitor',
...
)

我试着做了一个

$ ./manage.py migrate django_celery_monitor   # also tried for _results and _beat

但它会抛出同样的错误。

最佳答案

好的,问题出在管理模块中的一段代码,该代码试图在初始化期间检索 TaskState。因此,甚至在可以执行任何迁移之前就引发了异常。

关于django - 无法在现有 Django 项目上从头开始恢复数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47569628/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com