django.db.utils.IntegrityError: - error persists

168 Views Asked by At

this question has been discussed and answered here, however the error is persisting for me. As I don't have enough reputation I cant comment in that discussion yet.

I have followed the responses to remove on_delete=models.SET_DEFAULT and default=1 to run the initial migrate, however I receive the following error:

*tutorial_category = models.ForeignKey(TutorialCategory,verbose_name="Category", null=True)
TypeError: __init__() missing 1 required positional argument: 'on_delete'*

I'm assuming it needs the 'on_delete' field, and have tried on_delete.PROTECT and CASCADE, however this brings the original error:

*"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."*

I am using Django 2.2.9, any help on how to set up Foreignkeys would be appreciated.

thanks!

1

There are 1 best solutions below

2
Chetan Vashisth On

Try anyone of these:

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)