8
7

More than 5 years have passed since last update.

ArgumentError: Index name xx on xx already exists

Last updated at Posted at 2015-08-24

背景

開発中で『rake db:migrate』をすると、『ArgumentError: Index name xx on xx already exists』というエラーが出てきた。

おそらく、前同じ命令を実行する時、エラーになって、『rake db:rollback』の実行をわすれてしまって、そうなっちゃったじゃないかなあ。

対策

戻れる時

rake db:rollback

戻らない時

  • indexを確認する
ActiveRecord::Base.connection.tables.each do |table|
    puts ActiveRecord::Base.connection.indexes(table).inspect
end
  • テーブルを消せばいい

indexももちろん消してしまうので

ActiveRecord::Migration.drop_table :table_name

参照

8
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
7