我正在尝试在Rails 3.2.15中创建两个模型之间的多对多关系,但是出现了问题。这里有我的迁移代码:
class CreateTopicInterest < ActiveRecord::Migration
def change
create_join_table :users, :topics, table_name: :topic_interest do |t|
t.index :user_id
t.index :topic_id
t.integer :interest_type
t.timestamps
end
end
end
运行 "rake db:migrate" 后,这是终端输出的结果:
== CreateTopicInterest: migrating ============================================
-- create_join_table(:users, :topics, {:table_name=>:topic_interest})
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
undefined method `create_join_table' for #<CreateTopicInterest:0x007fe7ac8d86a0>/Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448@diver/gems/activerecord-3.2.15/lib/active_record/migration.rb:465:in `block in method_missing'
/Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448@diver/gems/activerecord-3.2.15/lib/active_record/migration.rb:438:in `block in say_with_time'
/Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448@diver/gems/activerecord-3.2.15/lib/active_record/migration.rb:438:in `say_with_time'
/Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448@diver/gems/activerecord-3.2.15/lib/active_record/migration.rb:458:in `method_missing'
/Users/duncanmalashock/rails_projects/diver/db/migrate/20140801151401_create_topic_interest.rb:3:in `change'
/Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448@diver/gems/activerecord-3.2.15/lib/active_record/migration.rb:407:in `block (2 levels) in migrate'
/Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448@diver/gems/activerecord-3.2.15/lib/active_record/migration.rb:407:in `block in migrate'
/Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448@diver/gems/activerecord-3.2.15/lib/active_record/connection_adapters/abstract/connection_pool.rb:129:in `with_connection'
/Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448@diver/gems/activerecord-3.2.15/lib/active_record/migration.rb:389:in `migrate'
/Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448@diver/gems/activerecord-3.2.15/lib/active_record/migration.rb:528:in `migrate'
/Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448@diver/gems/activerecord-3.2.15/lib/active_record/migration.rb:720:in `block (2 levels) in migrate'
/Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448@diver/gems/activerecord-3.2.15/lib/active_record/migration.rb:775:in `call'
/Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448@diver/gems/activerecord-3.2.15/lib/active_record/migration.rb:775:in `block in ddl_transaction'
/Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448@diver/gems/activerecord-3.2.15/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
/Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448@diver/gems/activerecord-3.2.15/lib/active_record/transactions.rb:208:in `transaction'
/Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448@diver/gems/activerecord-3.2.15/lib/active_record/migration.rb:775:in `ddl_transaction'
/Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448@diver/gems/activerecord-3.2.15/lib/active_record/migration.rb:719:in `block in migrate'
/Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448@diver/gems/activerecord-3.2.15/lib/active_record/migration.rb:700:in `each'
/Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448@diver/gems/activerecord-3.2.15/lib/active_record/migration.rb:700:in `migrate'
/Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448@diver/gems/activerecord-3.2.15/lib/active_record/migration.rb:570:in `up'
/Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448@diver/gems/activerecord-3.2.15/lib/active_record/migration.rb:551:in `migrate'
/Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448@diver/gems/activerecord-3.2.15/lib/active_record/railties/databases.rake:193:in `block (2 levels) in <top (required)>'