Skip to content

Unable to delete auth.users row due to objects_owner_fkey FK constraint #65

@liaujianjie

Description

@liaujianjie

Bug report

Describe the bug

When a user uploads an object to a bucket, the object's row in storage.objects has a column owner that has a FK constraint objects_owner_fkey to auth.users.id. However, it's not set up with on delete {cascade|set null}—which prevents the user from actually being deleted.

Attempting to delete a user with a storage.object referencing the user results in a FK constraint violation.

To Reproduce

  1. Create a user
  2. Authenticate as that user on the client
  3. Upload an object as that user on the client
  4. Delete that user via dashboard
  5. You'll get a FK constraint violation error:

    Deleting user failed: update or delete on table "users" violates foreign key constraint "objects_owner_fkey" on table "objects"

Expected behavior

Should be able to delete user whilst retaining the object in the database.

Suggested fix & temporary workaround

Add on delete set null to the objects_owner_fkey constraint:

alter table storage.objects
drop constraint objects_owner_fkey,
add constraint objects_owner_fkey
   foreign key (owner)
   references auth.users(id)
   on delete set null;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions