Users cant be deleted

  

When I try to delete a user via espaceurl/users, I get the error:

The DELETE statement conflicted with the REFERENCE constraint "OSFRK_OSUSR_S4Y_MYUSERTABLE_OSSYS_USER_USERID". The conflict occurred in database "ELJJSW017", table "dbo.OSUSR_S4Y_MYUSERTABLE", column 'USERID'. The statement has been terminated.

How should I delete users now?

Info: I'm using platform version 11, but I had the same problems with Outsystems 10

Hi Michael,

you are probably using that UserId (foreign key) on  one of the records (from another entity) on your app. 

Did you created a table called MyUserTable? probably that user Id is being used there. So before you be able to delete your users, you need to make sure you clear all the data that is referencing that user Id. 

Vera

Solution

This seems like a very straightforward error.
Let's take a look at this error message:

The DELETE statement conflicted with the REFERENCE constraint "OSFRK_OSUSR_S4Y_MYUSERTABLE_OSSYS_USER_USERID". The conflict occurred in database "ELJJSW017", table "dbo.OSUSR_S4Y_MYUSERTABLE", column 'USERID'. The statement has been terminated.

What this means is, that when trying to delete a record from User entity, a reference / linked attribute was found in "MyUserTable", specifically in the column called "UserId".
Therefore the SQL query was terminated.


So if you wish to remove a user, you need to ofcourse delete the reference to this user in all entities which use it.
Or you could just setup a cascading delete for this entity.

You can do this by going to your MyUserTable entitiy, and selecting the UserId attribute, here you set the Delete rule to Delete.

Solution