4

I'm trying to add a product data in my Strapi product, but sometimes it shows "Invalid input data. Please verify unique constraints" errors. Anyone have dealt with this before?

I got {statusCode: 400, error: "Bad Request", message: "Invalid input data. Please verify unique constraints"} in my console.

4 Answers 4

0

This happened to me due to mismatch in package versions. The ultimate solution that worked for me was to upgrade the package to 3.5.x.

More details here: https://github.com/strapi/strapi/issues/9369

Sign up to request clarification or add additional context in comments.

2 Comments

Hello, my version right now is 3.5.0, so I should just upgrade?
Yes, go ahead and update it to the latest version. That would probably fix the issue.
0

This happened to me because I was missing const axios = require('axios'); in some of my model files. I did webhooks myself for each model using axios to send a POST request.

Try npm run strapi console It was very helpful. It did show an erorr in a console with enough info, as I tried to update a field in a single type.

Maybe you missing something in your model/service/controller. Strapi console will reveal it, hopefully.

Comments

0

If this is in the context of lifecycle hooks, I got this error while trying to do one in v3.

My mistake was not adding another parameter to the beforeUpdate method

Before : 
async beforeUpdate(data) {
  console.log(data);
  data.ImageUrlTest = "testurlimage";
},


After:
async beforeUpdate(params, data) {
  console.log(params);
  data.ImageUrlTest = "testurlimage";
},

Comments

0

I ran into this same issue today. The "Invalid input data. Please verify unique constraints" displayed on the frontend seems to be a catch-all message and isn't always indicative of a unique constraint issue.

In my case, it was because the value I was trying to enter in a particular field was longer than the fields max length. We had the data type Short text selected for the field, but the particular value I was trying to save when the error occurred was 283 chars long.

You might find your issue to be a similar DB error being masked by the generic error message as well.

I was able to find this error by reading the Strapi server logs - this revealed the actual error message value too long for type character varying(255)

1|strapi-dev  | [2023-02-22T19:07:19.844Z] error error: insert into "components_resources_content_resource_sections" ("sectionBodyRichText", "sectionVideoUrl") values ($1, $2) returning * - value too long for type character varying(255)
1|strapi-dev  |     at Parser.parseErrorMessage (/home/ec2-user/content-creation-service/app/node_modules/pg-protocol/dist/parser.js:278:15)
1|strapi-dev  |     at Parser.handlePacket (/home/ec2-user/content-creation-service/app/node_modules/pg-protocol/dist/parser.js:126:29)
1|strapi-dev  |     at Parser.parse (/home/ec2-user/content-creation-service/app/node_modules/pg-protocol/dist/parser.js:39:38)
1|strapi-dev  |     at Socket.<anonymous> (/home/ec2-user/content-creation-service/app/node_modules/pg-protocol/dist/index.js:10:42)
1|strapi-dev  |     at Socket.emit (events.js:315:20)
1|strapi-dev  |     at Socket.EventEmitter.emit (domain.js:486:12)
1|strapi-dev  |     at addChunk (_stream_readable.js:309:12)
1|strapi-dev  |     at readableAddChunk (_stream_readable.js:284:9)
1|strapi-dev  |     at Socket.Readable.push (_stream_readable.js:223:10)
1|strapi-dev  |     at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
1|strapi-dev  | From previous event:
1|strapi-dev  |     at Child.<anonymous> (/home/ec2-user/content-creation-service/app/node_modules/bookshelf/lib/model.js:1160:42)
1|strapi-dev  | From previous event:
1|strapi-dev  |     at Child.<anonymous> (/home/ec2-user/content-creation-service/app/node_modules/bookshelf/lib/model.js:1159:14)
1|strapi-dev  |     at processImmediate (internal/timers.js:461:21)
1|strapi-dev  | From previous event:
1|strapi-dev  |     at Child.<anonymous> (/home/ec2-user/content-creation-service/app/node_modules/bookshelf/lib/model.js:1060:10)
1|strapi-dev  | From previous event:
1|strapi-dev  |     at runCreate (/home/ec2-user/content-creation-service/app/node_modules/strapi-connector-bookshelf/lib/queries.js:113:45)
1|strapi-dev  |     at wrapTransaction (/home/ec2-user/content-creation-service/app/node_modules/strapi-connector-bookshelf/lib/queries.js:52:29)
1|strapi-dev  |     at create (/home/ec2-user/content-creation-service/app/node_modules/strapi-connector-bookshelf/lib/queries.js:120:12)
1|strapi-dev  |     at Object.create (/home/ec2-user/content-creation-service/app/node_modules/strapi-connector-bookshelf/lib/queries.js:58:20)
1|strapi-dev  |     at fn (/home/ec2-user/content-creation-service/app/node_modules/strapi-database/lib/queries/helpers.js:31:54)
1|strapi-dev  |     at Object.create (/home/ec2-user/content-creation-service/app/node_modules/strapi-database/lib/queries/helpers.js:15:24)
1|strapi-dev  |     at async Promise.all (index 0)
1|strapi-dev  |     at async updateComponents (/home/ec2-user/content-creation-service/app/node_modules/strapi-connector-bookshelf/lib/queries.js:408:13)
1|strapi-dev  |     at async runUpdate (/home/ec2-user/content-creation-service/app/node_modules/strapi-connector-bookshelf/lib/queries.js:146:7)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.