in reply to Using DBIx::Class To Delete Row With Foreign Keys

Hi, I would allow DBIx::Class to manage the relationships, i.e. try removing 'REFERENCES user(id)' from your table schema. It's creating a database foreign key which is preventing the deletion, and as the doc says,

By default, DBIx::Class cascades deletes across has_many, has_one and might_have relationships. You can disable this behaviour on a per-relationship basis by supplying cascade_delete => 0 in the relationship attributes.

The cascaded operations are performed after the requested delete, so if your database has a constraint on the relationship, it will have deleted/updated the related records or raised an exception before DBIx::Class gets to perform the cascaded operation.

Hope this helps!


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: Using DBIx::Class To Delete Row With Foreign Keys
by varanasi (Scribe) on Jan 24, 2019 at 17:23 UTC

    Thanks. Likely I don't understand how cascades work. I thought using a cascade would delete my row in User if I delete the Member row that uses that key.