这个问题已经在这里讨论和回答了,但是错误对我来说仍然存在。 由于我没有足够的声誉,我还不能在该讨论中发表评论。
我已经按照响应删除on_delete=models.SET_DEFAULT
并default=1
运行初始迁移,但是我收到以下错误:
*tutorial_category = models.ForeignKey(TutorialCategory,verbose_name="Category", null=True)
TypeError: __init__() missing 1 required positional argument: 'on_delete'*
我假设它需要"on_delete"字段,并且已经尝试了on_delete.PROTECT and CASCADE
,但是这带来了原始错误:
*"django.db.utils.IntegrityError: The row in table 'main_tutorial' with primary key '1' has an invalid foreign key: main_tutorial.tutorial_series_id contains a value 'tutorial_series_id' that does not have a corresponding value in main_tutorialseries.id."*
我正在使用 Django 2.2.9,有关如何设置外键的任何帮助将不胜感激。
谢谢!
尝试以下任何一种:
tutorial_category = models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING,TutorialCategory,verbose_name="Category", null=True)
tutorial_category = models.ForeignKey(on_delete=models.CASCADE,TutorialCategory,verbose_name="Category", null=True)