DEV Community

cybin
cybin

Posted on

Error: "Unique index or primary key violation:"

Error due to manual insertion of values setting the primary keys in the data.sql file.

FAILURE example:
INSERT INTO role (id, roleName) VALUES (1, 'admin'), (2, 'user');

WORKING example:
INSERT INTO role (roleName) VALUES ('admin'), ('user');

Setting the ids manually only let us persist data from the last added row, all the previous ones will return you a Unique index or primary key violation: error.
So, for example, if we have 3 rows added in our data.sql, only the 4th persist operation will succeed.

Top comments (0)