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")
答案 0 :(得分:1)
使用表格&#34; appname.ModelName&#34;而不是导入模型。
user = models.ForeignKey("users.RegModel", ...)