-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"duplicate key value violates unique constraint" error when adding a new field #12493
Comments
What version of PostgreSQL are you using as this seems kinda related to #11723 |
I'm using |
Running in the same issue also when I try to change permission for public user on one single type: [2022-02-15 12:50:43.440] error: insert into "up_permissions" ("action", "created_at", "updated_at") values ($1, $2, $3) returning "id" - duplicate key value violates unique constraint "up_permissions_pkey"
error: insert into "up_permissions" ("action", "created_at", "updated_at") values ($1, $2, $3) returning "id" - duplicate key value violates unique constraint "up_permissions_pkey"
at Parser.parseErrorMessage (/Users/gvocale/Sites/strapi/node_modules/pg-protocol/dist/parser.js:287:98)
at Parser.handlePacket (/Users/gvocale/Sites/strapi/node_modules/pg-protocol/dist/parser.js:126:29)
at Parser.parse (/Users/gvocale/Sites/strapi/node_modules/pg-protocol/dist/parser.js:39:38)
at Socket.<anonymous> (/Users/gvocale/Sites/strapi/node_modules/pg-protocol/dist/index.js:11:42)
at Socket.emit (node:events:394:28)
at Socket.emit (node:domain:475:12)
at addChunk (node:internal/streams/readable:312:12)
at readableAddChunk (node:internal/streams/readable:287:9)
at Socket.Readable.push (node:internal/streams/readable:226:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23) |
By the way just tried version Strapi 4.0.8 and the issue persists. |
I should also add that it is not a Strapi bug. It's rather a PostgreSQL bug by design, that occurs after dump restores or mass imports. It occurs when the primary key sequence in the table you're working with goes out of sync - that is, when the current id_seq is less or equal to the max value. So, you technically would need to manually increment it (with the code above). |
@ibnlanre that helped! Thank you so much! |
Marking as closed as it was made clear this isn't a Strapi bug but a PostgreSQL issue on imports. |
@ibnlanre's answer did the trick for me. I had to tweak it a bunch so if anyone is hitting repeated errors such as:
Then try wrapping the table name in single quotes as well as doubles. My table was called
|
@Eli-Nathan I got the same error and it seems that the fix is updating the table sequence. |
@ibnlanre and @derrickmehaffy Hello, I am wondering it is the same issue I am facing now, after 216 products imports using import/export strapi plugin. Should I run the query you said after every mass imports?!!! that would be so frustrating if so. does switching to MySQL fix the issue? thanks a lot for any response. My environment: |
Not sure why we close this issue, but it seems this is an issue of the native Strapi entity service/query. After inserting the record with the id value into the database, it should automatically increase the sequence. It worked properly on the previous version, but after we upgrade to the latest version this issue is occurs. The code below is used to insert a new record into the database
I think the root cause might be because the id field that we paste into the entry object has a value, so the sequent didn't get increased. But we need to predefine the id value in order to we can associate with other models when seeding initial data. Worked version: 3.6.8 |
We are also seeing this error on multiple tables, despite not doing any importing. After implementing the fix in the db it works for a bit but then the sequence gets out of sync again somehow |
We see the same problem. For us this happens after we used a migration file to fill a table with initial data. Now we can edit existing items but not create new ones with exactly this the above problem. |
The same issue during migration from v4.5.1 to v4.6.1 |
Please this issue is NOT resolved. |
@derrickmehaffy will this be merged in soon if it hasn't? I keep getting this after creating a new collection type locally and pushing to production. Granted I'm using sqliite locally and postgres in production (which is default). |
@ibnlanre Thank you! |
This worked for me, but of course you empty the table completely; |
Bug report
Describe the bug
Sometimes, when adding a new field to a component, the following error appears.
Steps to reproduce the behavior
I have tried deleting the created field, running
rm -rf .cache
andyarn dev
again, but the error keeps happening and can't startyarn dev
successfully.Finally closing and reopening terminal, running
yarn dev
again, fixed it. Although adding again the fieldtextColor
reproduce again the issue.Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
Code snippets
Error
System
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: