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 }
Ok,用户希望在删除用户时将license中的引用设置为null,但不希望触及模式。我认为dependent: :nullify
对管理员(应用级别)的has_many
协会可能是解决方案
# admin
has_many :dont_know_the_association, dependent: :nullify