我收到了这个错误。
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/makemigrations.py", line 125, in handle
migration_name=self.migration_name,
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/autodetector.py", line 43, in changes
changes = self._detect_changes(convert_apps, graph)
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/autodetector.py", line 110, in _detect_changes
self.old_apps = self.from_state.concrete_apps
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/state.py", line 158, in concrete_apps
self.apps = StateApps(self.real_apps, self.models, ignore_swappable=True)
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/state.py", line 236, in __init__
raise ValueError(msg.format(field=operations[0][1], model=lookup_model)) ValueError: Lookup failed for model referenced by field systech_account.User.companies: systech_account.Company
每次我尝试
python manage.py makemigrations
在我的(Ubuntu)中。但是当我尝试在我的Windows和他们的同事(Ubuntu)上运行它时,它可以正常运行。 (*我们通过Git repo分享项目)。他们可以成功地进行迁移。我们想知道为什么这会发生在我的电脑上。
注意:
我们尝试过的解决方案:
谢谢! :)
答案 0 :(得分:2)
我将在这里猜测systech_account.Company
是一个在应用程序中尚未加载的模型,同时尝试为其他应用程序创建迁移。
如果这是真的,首先运行
可能是可以解决的makemigrations app_that_has_company_in_it
在运行其他makemigrations
之前。
但这不是解决方案。
您和您的同事都在尝试进行相同的迁移这一事实告诉我,您不会将迁移存储在源代码管理中,这是真正的问题。
执行此确实可以阻止这些错误发生(至少对我/我们而言)并且在尝试进行迁移时更快,因为没有任何重复的步骤。如果你担心与这些合并冲突,你不必担心,django非常聪明。