1

I have an Account model that has one page table records when I'm trying to delete/destroy an account instance Activerecords gave me an exception ForiegnKey even I defined in the account model.

the error is: PG::ForeignKeyViolation: ERROR: update or delete on table "accounts" violates foreign key constraint "fk_rails_a01c5b1985" on table "pages" DETAIL: Key (id)=(1) is still referenced from table "pages". : DELETE FROM "accounts" WHERE "accounts"."id" = $1

Account.rb

has_one :page, dependent: :destroy

Please give me solution how can I achieve all dependent record also deleted/destroyed when a parent record is deleted without any exception.

Rana. Amir
  • 187
  • 3
  • 15

0 Answers0