django makemigrations导入错误

时间:2017-02-19 21:45:33

标签: python django

  File "E:\PhytonProgects\natarelke\users\models.py", line 6, in <module>
    from catalog.models import Dish
  File "E:\PhytonProgects\natarelke\catalog\models.py", line 5, in <module>
    from users.models import RegModel
ImportError: cannot import name RegModel

尝试执行makemigrations但如果我删除from users.models import RegModel则会出错,我会再给出一个错误

  File "E:\PhytonProgects\natarelke\catalog\models.py", line 115, in Review
user = models.ForeignKey(RegModel, verbose_name=u'123',
NameError: name 'RegModel' is not defined

我如何解决它?在表

中添加dish字段后添加
class UserFavs(models.Model):
    user = models.ForeignKey(RegModel, verbose_name=u'Пользователь',
                             related_name="user", null=True)
    dish = models.ForeignKey(Dish, verbose_name=u'Блюдо',
                             related_name="dish")

1 个答案:

答案 0 :(得分:1)

使用表格&#34; appname.ModelName&#34;而不是导入模型。

user = models.ForeignKey("users.RegModel", ...)