新手问题 Rails 组合索引,看书上来的,为什么会有错误?

yirolhao · January 14, 2017 · Last by yirolhao replied at January 14, 2017 · 3031 hits

google 了错误,可是没有什么结果。 迁移代码

class CreateRelationships < ActiveRecord::Migration[5.0]
  def change
    create_table :relationships do |t|
      t.integer :follower_id
      t.integer :followed_id

      t.timestamps
    end
  end
  add_index :relationships, :follower_id
  add_index :relationships, :followed_id
  add_index :relationships, [:follower_id, :followed_id], unique: true
end

错误消息:

-- add_index(:relationships, :follower_id)

-- add_index(:relationships, :follower_id)

rails aborted!

ActiveRecord::StatementInvalid: Mysql2::Error: Table 'blog_demo_development.relationships' doesn't exist: CREATE INDEX index_relationships_on_follower_id ON relationships (follower_id)

add_index 写到 def change ; end 里面。

yirolhao closed this topic. 14 Jan 12:34
yirolhao closed this topic. 14 Jan 12:35
You need to Sign in before reply, if you don't have an account, please Sign up first.