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".
我已經有了 belongs_to :approved_by_admin, class_name: 'Admin', optional: true
但是仍然給我這個錯誤,為什么?
add_reference :licences, :approved_by_admin, foreign_key: { to_table: :users }
uj5u.com熱心網友回復:
好的,用戶希望在洗掉用戶時將許可證中的參考設定為空,但不想接觸架構。我認為管理員協會(應用dependent: :nullify程式has_many級別)可能是解決方案
# admin
has_many :dont_know_the_association, dependent: :nullify
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/460248.html
