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

yirolhao · 2017年01月14日 · 最后由 yirolhao 回复于 2017年01月14日 · 3028 次阅读

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 关闭了讨论。 01月14日 12:34
yirolhao 关闭了讨论。 01月14日 12:35
需要 登录 后方可回复, 如果你还没有账号请 注册新账号