gpt4 book ai didi

python - Django 自定义用户在同步数据库时在运行时遇到导入问题

转载 作者:行者123 更新时间:2023-12-01 05:32:03 26 4
gpt4 key购买 nike

我在 app.models 中定义了一个自定义 User 模型。它还在 AUTH_USER_MODEL 设置中正确定义为 app.User。当我运行该网站时,一切都运行良好。

但是,当我运行 ./manage.pysyncdb --migrate 时,它会因以下回溯而中断:

Traceback (most recent call last):
File ".virtualenv/lib/python2.7/site-packages/django/core/management/base.py", line 222, in run_from_argv
self.execute(*args, **options.__dict__)
File ".virtualenv/lib/python2.7/site-packages/django/core/management/base.py", line 255, in execute
output = self.handle(*args, **options)
File ".virtualenv/lib/python2.7/site-packages/django/core/management/base.py", line 386, in handle
return self.handle_noargs(**options)
File ".virtualenv/lib/python2.7/site-packages/south/management/commands/syncdb.py", line 103, in handle_noargs
management.call_command('migrate', **options)
File ".virtualenv/lib/python2.7/site-packages/django/core/management/__init__.py", line 161, in call_command
return klass.execute(*args, **defaults)
File ".virtualenv/lib/python2.7/site-packages/raven/contrib/django/management/__init__.py", line 37, in new_execute
return original_func(self, *args, **kwargs)
File ".virtualenv/lib/python2.7/site-packages/django/core/management/base.py", line 255, in execute
output = self.handle(*args, **options)
File ".virtualenv/lib/python2.7/site-packages/south/management/commands/migrate.py", line 111, in handle
ignore_ghosts = ignore_ghosts,
File ".virtualenv/lib/python2.7/site-packages/south/migration/__init__.py", line 233, in migrate_app
migrator.load_initial_data(target, db=database)
File ".virtualenv/lib/python2.7/site-packages/south/migration/migrators.py", line 224, in load_initial_data
call_command('loaddata', 'initial_data', verbosity=self.verbosity, database=db)
File ".virtualenv/lib/python2.7/site-packages/django/core/management/__init__.py", line 161, in call_command
return klass.execute(*args, **defaults)
File ".virtualenv/lib/python2.7/site-packages/raven/contrib/django/management/__init__.py", line 37, in new_execute
return original_func(self, *args, **kwargs)
File ".virtualenv/lib/python2.7/site-packages/django/core/management/base.py", line 254, in execute
self.validate()
File ".virtualenv/lib/python2.7/site-packages/django/core/management/base.py", line 285, in validate
raise CommandError("One or more models did not validate:\n%s" % error_text)
CommandError: One or more models did not validate:
auth.user: Model has been swapped out for 'app.User' which has not been installed or is abstract.

当我运行 ./manage.pysyncdb --migrate app 时,一切都运行正常,所以我不明白这里发生了什么。有人知道吗?

编辑:我安装的应用程序的顺序:

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
'django.contrib.webdesign',
'django.contrib.staticfiles',
'djcelery',
'app',

'babeldjango',
'debug_toolbar',
'template_timings_panel',
'devserver',
'django_extensions',
'djrill',
'facebook_tag',
'gunicorn',
'haystack',
'markitup',
'modeltranslation',
'raven.contrib.django',
'reversion',
'rosetta',
'sorl.thumbnail',
'south',
'statictastic',
'storages',
'twitter_tag',
'zebra',
'djcelery',
'djmoney_rates'
)

编辑 2:该问题似乎是由第三方应用程序中运行的迁移引起的。如果我注释掉那些有迁移的应用程序,一切都会顺利进行。我想这也是预期的,因为 ./manage.py migrate app 工作正常,但 ./manage.py migrate (为所有应用程序运行迁移)却不能。根据这些信息和跟踪,当第三方应用程序的迁移运行时,我的应用程序的模型似乎根本不可用。

最佳答案

遇到同样的问题,从 South 0.8.3 迁移到 South 0.8.4 解决了

在这里看到解决方案:http://south.aeracode.org/ticket/1179

关于python - Django 自定义用户在同步数据库时在运行时遇到导入问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19979934/

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