PG::ForeignKeyViolation: ERROR: update or delete on table "users" violates foreign key constraint "fk_rails_c98ef61810" on table "licences"
DETAIL: Key (id)=(7) is still referenced from table "licences".
I already have belongs_to :approved_by_admin, class_name: 'Admin', optional: true
But STill gives me this error why ?
add_reference :licences, :approved_by_admin, foreign_key: { to_table: :users }
CodePudding user response:
Ok, the user want to set to null the reference in licenses when a user is deleted, but does not want to touch the schema. I think a dependent: :nullify
on the has_many
association for admins (application level) might be the solution
# admin
has_many :dont_know_the_association, dependent: :nullify