You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using a unique constraint on a column in a table along with DeletedAt
I have a scenario where I would like to add a unique constraint on a name column and also use DeletedAt with mysql but looks like mysql doesnt allow custom indexes like a index on name and DeleteAt which makes it a bit not straight forward since unique index on just the name fails when a row with same name is previously deleted
Expected answer
Is there an in-built way to handle unique constraints for mysql using gorm that allows me to add a same name when the previous one is soft deleted
The text was updated successfully, but these errors were encountered:
Not a DB expert but I stumbled on your question, and looking at the gorm docs and SQL docs in general,
It should be doable, but adding a constrain in multiple fields, using Unique Indexes
eg (not really a valid sql, just what I gathered around)
CREATE UNIQUE INDEX a_unique_constrain ON your_table (name);
If I understand it correctly those 2 are considered unique and you can have them
Not a DB expert but I stumbled on your question, and looking at the gorm docs and SQL docs in general, It should be doable, but adding a constrain in multiple fields, using Unique Indexes
eg (not really a valid sql, just what I gathered around) CREATE UNIQUE INDEX a_unique_constrain ON your_table (name);
If I understand it correctly those 2 are considered unique and you can have them
Using a unique constraint on a column in a table along with DeletedAt
I have a scenario where I would like to add a unique constraint on a name column and also use DeletedAt with mysql but looks like mysql doesnt allow custom indexes like a index on name and DeleteAt which makes it a bit not straight forward since unique index on just the name fails when a row with same name is previously deleted
Expected answer
Is there an in-built way to handle unique constraints for mysql using gorm that allows me to add a same name when the previous one is soft deleted
The text was updated successfully, but these errors were encountered: