依赖破坏不起作用给出了外键异常

时间:2019-01-17 10:34:58

标签: ruby-on-rails ruby rails-activerecord

当我尝试删除/销毁帐户实例时,我有一个具有一页表记录的Account模型,即使我在该帐户模型中定义了ActiveRecords也会给我一个例外ForiegnKey

错误是: 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

请给我解决方案,如何在删除父记录时无一例外地实现所有相关记录也被删除/销毁。

0 个答案:

没有答案