django.db.utils.IntegrityError: duplicate key value violates unique constraint “django_content_type_pkey”

前端 未结 5 1796
春和景丽
春和景丽 2020-12-31 00:43

Ran into a bit of a problem, i\'m getting the above error message when i run \'python manage.py syncdb\' I\'m working on a fairly old site. It\' running django

5条回答
  •  猫巷女王i
    2020-12-31 01:24

    This usually means that your primary key sequence has gone out of sync. This may have been caused by a bad migration etc..
    To fix this;
    1. Start the dbshell
    python manage.py dbshell
    2. Find the current highest value of the primary key
    select max(id) from django_content_type;
    3. Change the primary key sequence to now start at a value higher than the value found in step 2.
    So assuming the value returned in step 2 was 290780 then alter sequence to start at a number greater than 290780
    alter sequence django_content_type_id_seq restart with 295000;

提交回复
热议问题