IntegrityError duplicate key value violates unique constraint - django/postgres

后端 未结 11 1058
清歌不尽
清歌不尽 2020-11-28 18:44

I\'m following up in regards to a question that I asked earlier in which I sought to seek a conversion from a goofy/poorly written mysql query to postgresql. I believe I suc

11条回答
  •  一个人的身影
    2020-11-28 19:39

    I was getting the same error as the OP.

    I had created some Django models, created a Postgres table based on the models, and added some rows to the Postgres table via Django Admin. Then I fiddled with some of the columns in the models (changing around ForeignKeys, etc.) but had forgotten to migrate the changes.

    Running the migration commands solved my problem, which makes sense given the SQL answers above.

    To see what changes would be applied, without actually applying them:
    python manage.py makemigrations --dry-run --verbosity 3

    If you're happy with those changes, then run:
    python manage.py makemigrations

    Then run:
    python manage.py migrate

提交回复
热议问题