在ActionRecord中有一个名为index_exists?
的函数,但是Rails 4.2.7没有foreign_key_exists?
。
因此,在一些数据库上调用remove_foreign_key:parties,franchise_groups
时会出现错误。
我应该使用什么?
更新
我的代码
class RemoveForeignKey < ActiveRecord::Migration
def up
if foreign_key_exists?(:parties, :franchise_groups)
remove_foreign_key :parties, :franchise_groups
end
end
end
出现错误
== 20161107163800 RemoveForeignKey: migrating =================================
-- foreign_key_exists?(:parties, :franchise_groups)
rake aborted!
An error has occurred, all later migrations canceled:
undefined method `foreign_key_exists?' for #<RemoveForeignKey:0x00000007ea0b58>
/home/rje/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.7/lib/active_record/migration.rb:664:in `block in method_missing'
up
方法内检查self.class.included_modules.include?(ActiveRecord::ConnectionAdapters::SchemaStatements)
吗? - Andrey Deinekoputs self.class.included_modules.include?(ActiveRecord::ConnectionAdapters::SchemaStatements)
只是给我一个错误uninitialized constant ConnectionAdapters
。也许在 Rails 4.2 上不存在这个东西? - Richardif foreign_keys(:accounts).include?(foreign_key_name)
。 - Andrey Deineko