无法删除ActiveRecord对象,外键约束失败

时间:2013-05-24 20:12:15

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

Rails 2.3 我试过的......

>> Import::Subscription.all(:conditions => ["account_id = ?", "44"]).destroy_all
NoMethodError: undefined method 'destroy_all' for #<Array:0x106ab4d78>

>> Import::Subscription.all(:conditions => ["account_id = ?", "44"])
>> @subs = _
>> @subs.each { |s| s.destroy }
ActiveRecord::StatementInvalid: Mysql::Error: Cannot delete or update a parent row: a
foreign key constraint fails

@subs[0].delete
ActiveRecord::StatementInvalid: Mysql::Error: Cannot delete or update a parent row: a
foreign key constraint fails

1 个答案:

答案 0 :(得分:0)

第二次尝试工作,只是一个愚蠢的fk问题。