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

最佳答案

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

关于mysql - 无法删除ActiveRecord对象,外键约束失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16742923/

10-12 18:19