I have a column that is unique Thread name and when I soft delete whatever it stays in the database still as expected, but when I try to re-create something with the same name it says its unique and cannot be created, how can I use the soft delete with unique names?

Comment From: ready4god2513

You would have to reassign the value upon delete. So something like thread.Name = fmt.Sprintf("del_%v_%v", time.Now().Unix(), thread.Name)

Then when you want to restore it you would just remove the prefix off of the value.

Comment From: jinzhu

Few options:

1, Use ThreadName & DeletedAt as combined unique index 2, Don't use DeletedAt 3, Rename old threadName 4, Delete it permanently when Unscoped https://github.com/jinzhu/gorm#soft-delete

Comment From: khash

@jinzhu based on the interpretation of all major databases from the unique index definition of SQL92, NULL values don't count as unique and therefore the first option (including DeletedAt in the index) is not going to work.

While having a timestamp for delete is a good idea for soft deletes (for example when used for "deleted since" scenarios), it seems a better approach could be being able to configure or set the value of DeleteAt that constitutes a non-deleted item (for example 0001-01-01 00:00:00 instead of NULL)

Comment From: okiiko

@jinzhu based on the interpretation of all major databases from the unique index definition of SQL92, NULL values don't count as unique and therefore the first option (including DeletedAt in the index) is not going to work.

While having a timestamp for delete is a good idea for soft deletes (for example when used for "deleted since" scenarios), it seems a better approach could be being able to configure or set the value of DeleteAt that constitutes a non-deleted item (for example 0001-01-01 00:00:00 instead of NULL)

@khash Have you solve this problem?

Comment From: shamuhammetylyas

@jinzhu based on the interpretation of all major databases from the unique index definition of SQL92, NULL values don't count as unique and therefore the first option (including DeletedAt in the index) is not going to work.

While having a timestamp for delete is a good idea for soft deletes (for example when used for "deleted since" scenarios), it seems a better approach could be being able to configure or set the value of DeleteAt that constitutes a non-deleted item (for example 0001-01-01 00:00:00 instead of NULL)

@khash Have you solve it???