Index name 'index_authorizations_on_user_id' on table 'authorizations' already exists
ArgumentError: Index name 'index_authorizations_on_user_id' on table 'authorizations' already exists
所以我去检查了架构,表已经存在。那么为什么会失败呢?通常在过去,它只会在进行迁移时生成新的表条目/更新,那么为什么它不直接忽略它呢?
我尝试进行回滚并得到: 此迁移使用remove_columns,该迁移不会自动逆转。
我尝试过执行 bin/rails db:migrate RAILS_ENV=development ,但遇到了同样的错误。
我已经完成了 db:reset、db:drop,这一切都回到了我无法运行的待处理迁移的问题。我做错了什么?
他们添加了以下迁移:20171024074328_create_authorizations.rb
class CreateAuthorizations < ActiveRecord::Migration[5.1]
def change
create_table :authorizations do |t|
t.string :provider
t.string :uid
t.references :user, foreign_key: true
t.timestamps
add_index :authorizations, :user_id
add_index :authorizations, [:provider, :uid], unique: true
end
end
结束
t.references :user, foreign_key: true
为您添加
authorizations.user_id
上的索引。如果您检查
references
文档,它会指向您
add_reference
,上面写着:
因此,当您调用添加适当的索引。默认为 true。 [...]
:index
index: true
时,
t.references :user
是默认值,并且创建的索引与
add_index :authorizations, :user_id
创建的索引相同。
不喜欢这有效的事实。
解决方案是删除具有unique
约束的索引列,然后重新索引