我遇到Django 1.7与特定部署的新App Registry有关的问题。通常我会吹掉实例并重新创建它,但是当我销毁实例时它会继续发生。
产品应用程序始终会导致此错误,我使用app.py文件将标签更改为sc_products,但现在sc_products已经定义了。
在这个特定的例子中,我试图迁移应用程序。
Running migrations:
Applying sc_products.0001_initial...Traceback (most recent call last):
File "manage.py", line 9, in <module>
execute_from_command_line(sys.argv)
File "/home/savingschampion/.virtualenvs/savings_champion/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/savingschampion/.virtualenvs/savings_champion/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/savingschampion/.virtualenvs/savings_champion/local/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/savingschampion/.virtualenvs/savings_champion/local/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/home/savingschampion/.virtualenvs/savings_champion/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 160, in handle
executor.migrate(targets, plan, fake=options.get("fake", False))
File "/home/savingschampion/.virtualenvs/savings_champion/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 63, in migrate
self.apply_migration(migration, fake=fake)
File "/home/savingschampion/.virtualenvs/savings_champion/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 91, in apply_migration
if self.detect_soft_applied(migration):
File "/home/savingschampion/.virtualenvs/savings_champion/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 135, in detect_soft_applied
apps = project_state.render()
File "/home/savingschampion/.virtualenvs/savings_champion/local/lib/python2.7/site-packages/django/db/migrations/state.py", line 57, in render
self.apps = Apps([AppConfigStub(label) for label in sorted(self.real_apps + list(app_labels))])
File "/home/savingschampion/.virtualenvs/savings_champion/local/lib/python2.7/site-packages/django/apps/registry.py", line 56, in __init__
self.populate(installed_apps)
File "/home/savingschampion/.virtualenvs/savings_champion/local/lib/python2.7/site-packages/django/apps/registry.py", line 89, in populate
"duplicates: %s" % app_config.label)
django.core.exceptions.ImproperlyConfigured: Application labels aren't unique, duplicates: sc_products
我已经在那里做了以下回答:
答案 0 :(得分:3)
我遇到了同样的问题而且偶然发现了这个问题。在调试django一段时间后,我可能会为你找到期待已久的答案。
这种情况最有可能发生,因为您的应用程序最终被同时视为未迁移和迁移(因此即使您更改了应用程序标签也会产生相同的错误),而这又发生了,因为您的应用程序已经老了式(南)迁移和新式(django)迁移。
处理这个问题的最好和最简单的方法是重新开始。删除所有已编号的迁移(例如rm migrations/0???_*.py*
)并重新致电manage.py makemigrations
,确保只保留django迁移并保持最新状态。
答案 1 :(得分:1)
检查您的INSTALLED_APPS。我不小心将同一个应用程序列出了两次并出现了类似的错误。