V8-archive: Duplicate key error after soft-delete in "directus_users"

Created on 14 Apr 2020  Â·  10Comments  Â·  Source: directus/v8-archive

Bug Report

Currently it is not possible to add a User with the email address of a previously deleted User.

Steps to Reproduce

  1. Go to Users
  2. Add a User with an email "[email protected]"
  3. Delete the user again
  4. Add another User with the email "[email protected]"

Expected Behavior

As per Users Dokumentation Users are only soft-deleted and it should be possible to create a new User with the same email address, that will take over the history of the previously existing user.

Actual Behavior

An error is displayed: Duplicate key "[email protected]" for collection "directus_users"

Other Context & Screenshots

Technical Details

  • Device: Desktop
  • OS: OSX
  • Web Server: Apache
  • PHP Version: 7.3
  • Database: MySQL 5.7
  • Directus Release Version: v8.6.2
  • Install Method: docker
bug enhancement needs more info api

Most helpful comment

Thanks for reacting so quickly and BTW I completely forgot to mention: I am a huge fan of directus!

The main problem with this issue is, that there is no way to bring back the soft-deleted users for admins or even via the API. If there would be a way to also show and edit the "deleted" users, then in a way, the problem would solve itself.

All 10 comments

We'll have to think through this as a bigger solution. The question becomes: what should happen to unique values when using soft delete. If you soft delete something, the record persists, and the unique value is still taken.

We could create a special case for users that it will "take over" the record from the previously deleted one, but I'd rather come up with a flow that isn't hardcoded for a single directus collection

@benhaynes @WoLfulus @shealavington any bright ideas?

Well, for Users I would imagine adding a user that _previously_ existed would prompt to "re-enable" them.

For a solution that works everywhere, the only real option is to pull the item from the collection and store it elsewhere. Matching schema with a "trash" table would be super annoying, so I would recommend using Activity/Revisions to store the "final state". We might already be doing this — in which case we could remove the "soft-delete" feature from status and focus on making activity/revisions more robust (including "staged draft" changes on items that are already published).

Thanks for reacting so quickly and BTW I completely forgot to mention: I am a huge fan of directus!

The main problem with this issue is, that there is no way to bring back the soft-deleted users for admins or even via the API. If there would be a way to also show and edit the "deleted" users, then in a way, the problem would solve itself.

This is actually something we're actively working on as we speak within Directus 9. Admins will be able to see all soft-deleted items, and will have dedicated UI buttons for "Delete Forever" and "Restore".

Looking forward to see Number 9 in action then! Thanks for all your work!

Any update with this issue? I've met exactly the same issue.

Good Day

Is there any way in version 8 that I can bring the user back?

Can I just delete the user in the database table??? (I should then be able to re-create it)

Please note that you can just connect to your database and then change the following(in my case I used mysql client):

  • SELECT directus (select the db in your database)
  • SELECT * FROM directus_users; (this will show you everything in the table and you can look for the user)

UPDATE directus_users (this is the table within the database)
SET status = 'active'
WHERE id = 1; (ID of the user)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

24js picture 24js  Â·  3Comments

cdwmhcc picture cdwmhcc  Â·  3Comments

magikstm picture magikstm  Â·  3Comments

benhaynes picture benhaynes  Â·  4Comments

vuhrmeister picture vuhrmeister  Â·  3Comments