django.db.utils.IntegrityError:

后端 未结 10 668
忘掉有多难
忘掉有多难 2021-01-21 07:47

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

10条回答
  •  长情又很酷
    2021-01-21 07:50

    I had this issue a while ago. The above answer maybe correct but it didnt work for me because -im using postgres, i cant just delete the database -migration files were commited in git.

    My situation was, I have 004 migration file but i cant run it because of IntegrityError.

    I checked the file, and i saw it was in operation list.

    The first item of list is migrations.CreateModel and the second was migrations.AddField

    here are my steps:

    1. I commented the second item in list, only the CreateModel is remaining.

    2. then run the migrate

    3. open the django admin page and add it manually the missing id you can add it also in database editor or update statement.

    4. uncomment the AddField section and rerun the migrate.

提交回复
热议问题