0

我正在和几个人一起开发一个应用程序。我在做前端。

最近,我搞砸了迁移。在尝试修复它们几个小时后,我删除了所有表,并再次克隆了 repo。

由于没有迁移文件,我运行manage.py makemigrations(由于某种原因,它没有检测到所有应用程序,只检测其中一个,我必须makemigrations为每个应用程序手动调用)。

然后,我运行manage.py migrate. 我收到以下错误:

Related model 'User.user' cannot be resolved

由于 User 表与 User 表具有 OneToOneField 关系。此外,其他表也相互依赖。

我对这个问题的看法是注释掉所有导致问题的字段,进行迁移,取消注释,然后再次进行迁移。

我应该如何解决它?

4

1 回答 1

0

Ok, I solved this particular problem:

In User app there was another model, which referred to User. Automatically created migration file had this model before User model, so the script failed, since it could not refer to a model that is yet not created.

I solved this by editing the migration file, swapping the order of creating models - so the second model can refer to the first one.

于 2021-02-27T03:09:03.247 回答