Pkey violates unique constraint after Seed

After i add data to the DB with some data and i try to do an insert, i get the error: duplicate key value violates unique constraint "users_pkey". I can get around it by
await db.execute(sql.raw(
`ALTER SEQUENCE users_id_seq RESTART WITH ${Math.max(...users.map(u => u.id)) + 1}`
));
await db.execute(sql.raw(
`ALTER SEQUENCE users_id_seq RESTART WITH ${Math.max(...users.map(u => u.id)) + 1}`
));
but i was wondering if there was something im doing wrong when inserting? I dont use seed and have a script that runs and inserts data to the db, basicalli make to db connections. Not sure if that affects it
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?