Strapi Version : 4.1.7:
Operating System : Ubuntu:
Database : Postgress:
Node Version : 14.18:
NPM Version : 6.14:
Yarn Version : 1.22:
Whenever I am trying to update Schema Model it’s giving me an error I already have a field in database if i add that field in the model I am getting an error.
which is given below
( Merchant is model name )
[2022-07-05 08:14:13.551] debug: Server wasn’t able to start properly.
[2022-07-05 08:14:13.556] error: alter table “merchants” add constraint “merchants_merchant_unique” unique (“merchant”) - could not create unique index “merchants_merchant_unique”
error: alter table “merchants” add constraint “merchants_merchant_unique” unique (“merchant”) - could not create unique index “merchants_merchant_unique”
at Parser.parseErrorMessage (/home/krishna/ubuntu/hotbuyer/node_modules/pg-protocol/dist/parser.js:287:98)
at Parser.handlePacket (/home/krishna/ubuntu/hotbuyer/node_modules/pg-protocol/dist/parser.js:126:29)
at Parser.parse (/home/krishna/ubuntu/hotbuyer/node_modules/pg-protocol/dist/parser.js:39:38)
at Socket. (/home/krishna/ubuntu/hotbuyer/node_modules/pg-protocol/dist/index.js:11:42)
at Socket.emit (events.js:376:20)
at Socket.emit (domain.js:470:12)
at addChunk (internal/streams/readable.js:309:12)
at readableAddChunk (internal/streams/readable.js:284:9)
at Socket.Readable.push (internal/streams/readable.js:223:10)
at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
Welcome to the Strapi Community @Shubham_Digole
I know there have been several bug fixes after 4.1.7 so make sure you are on the latest version.
Could you make sure your running the latest version then try it again ?
Agree. Please use the latest strapi. Also as I can see the error, looks like you are trying to add the unique constrain in the field, if yes, you can do it using below code.
Column field is used to update the existing column schema within the table.
Thanks for the solution but still I am getting the same error and I can’t update the version for not because a lot of other things going on there. can you suggest any other solution
i updated the strapi still same error
Please don’t mark a solution if it’s not a solution.
remove the unique part of it, to see if it changes.
Also is that the whole
merchamts model from your models file ?
sorry for solution remark
and also removed unique part still same error
and below is my model
still same error
Have you set automigration on ? So your model actually changes ?
no i did not set automigration on can you tell me how to do that
I’m not sure if it’s valid in 4 but I know it was in 3 So it might been removed as I can’t find it in the docs for V4 but I found it for V3.
To me it seems it’s trying to create something and it’s set to unique but you can’t unset it as it’s unique.
So might have to login to the database and change the field to not be unique.
i am trying with another fields which are not unique still getting same error
But you have to fix that field not other fields
i just tried to add other fieds to see if that fields adds bur same error and also tried making slug field not unique and still same error
What the error is saying is the database has set it as unique, and you have to fix it before you can do other fields as well.
Presume you can use a GUI tool to remove the unique constrain to fix it.
Hi thank you for help found out that In my database there were same properties having same name that’s why i was getting unique error i just fixed it and its working fine
thanks for help