I need a help regarding django.db.utils.IntegrityError: I read similar questions on stackoverflow before posting a new question, but I could not find the right solution.
Basically, I am following a course, let's say copy-pasting the code in models.py, serializers.py views.py And whenever I call python manage.py migrate, I get this error:
django.db.utils.IntegrityError: The row in table 'LittleLemonAPI_menuitem' with primary key '1' has an invalid foreign key: LittleLemonAPI_menuitem.category_id contains a value '1' that does not have a corresponding value in LittleLemonAPI_category.id.
Anyone can help, how could I fix that error? The strange part is, that I literally follow each step on the course, it isn't even my code, and I can't figure out what's wrong.
I tried to delete all migration related files and db.sqlite3, but in that way I lose all the previously entered data.
I tried changing the part from on_delete.PROTECT, default=1. into. on_delete.CASCADE and removing default1, but nothing worked.