Django integrity error while running migration
Recently I’ve got an error when invoking python manage.py migrate
1 | Traceback (most recent call last): |
This one means that you have out of date sequence within your database (improper previous migrations or jumps between different versions of code which leads to migrations being applied in chaotic order can cause this broken state). To quickly workaround this issue you can manually update values in your database. Go with python manage.py dbshell
and check current values
1 | SELECT last_value FROM django_migrations_id_seq; |
Then update them with a command below (any sane values that are greater than ones from output above). Usually first command is enough but if you are still getting errors with key value violates unique constraint "django_content_type_pkey"
you need to run second one as well (you might need to alter auth_permission_id_seq
too depending on your database state)
1 | ALTER SEQUENCE django_migrations_id_seq RESTART WITH 101; |