After importing data in PostgreSQL, duplicate key value violates unique constraint

后端 未结 4 954
忘了有多久
忘了有多久 2021-02-02 17:51

I recently migrated my rails app to PostgreSQL in order to take advantage of fulltext search.

Since the migration coincided with moving to a new webhost, the steps for m

4条回答
  •  情深已故
    2021-02-02 18:16

    Another way is remove the primary key (id) from the columns (or don't dump the id). So your data would look like

    INSERT INTO book (name, price) VALUES ('Alchemist' , 10);
    

    instead of

    INSERT INTO book (id, name, price) VALUES (1 , 'Alchemist' , 10);
    

    This way, you won't have to reset the primary key after loading initial data

提交回复
热议问题