LoginSignup
0
0

More than 3 years have passed since last update.

AWSで自動デプロイした時、ArgumentError: Index name 'index_boards_on_user_id' on table 'boards' already existsが出た際の解決法

Last updated at Posted at 2021-05-02

開発環境

AWSサーバー使用
自動デプロイツールcapistrano使用

状況

ローカル環境で、データベースを一度削除し、作り直して、'bundle exec cap production deploy'コマンドを実行した際に、以下のようなエラーが出た。

Caused by:
 DEBUG [7ec9cb7c]   ArgumentError: Index name 'index_boards_on_user_id' on table 'boards' already exists
 DEBUG [7ec9cb7c]   /var/www/forum-lastapp/shared/bundle/ruby/2.6.0/gems/activerecord-6.0.3.6/lib/active_record/connection_adapters/abstract/schema_statements.rb:1197:in `add_index_options'
/var/www/forum-lastapp/shared/bundle/ruby/2.6.0/gems/activerecord-6.0.3.6/lib/active_record/connection_adapters/mysql/schema_creation.rb:65:in `index_in_create'
/var/www/forum-lastapp/shared/bundle/ruby/2.6.0/gems/activerecord-6.0.3.6/lib/active_record/connection_adapters/abstract/schema_creation.rb:49:in `block in visit_TableDefinition'
/var/www/forum-lastapp/shared/bundle/ruby/2.6.0/gems/activerecord-6.0.3.6/lib/active_record/connection_adapters/abstract/schema_creation.rb:49:in `map'
/var/www/forum-lastapp/shared/bundle/ruby/2.6.0/gems/activerecord-6.0.3.6/lib/active_record/connection_adapters/abstract/schema_creation.rb:49:in `visit_TableDefinition'
/var/www/forum-lastapp/shared/bundle/ruby/2.6.0/gems/activerecord-6.0.3.6/lib/active_record/connection_adapters/abstract/schema_creation.rb:14:in `accept'
/var/www/forum-lastapp/shared/bundle/ruby/2.6.0/gems/activerecord-6.0.3.6/lib/active_record/connection_adapters/abstract/schema_statements.rb:315:in `create_table'
/var/www/forum-lastapp/shared/bundle/ruby/2.6.0/gems/activerecord-6.0.3.6/lib/active_record/connection_adapters/mysql/schema_statements.rb:81:in `create_table'
/var/www/forum-lastapp/shared/bundle/ruby/2.6.0/gems/activerecord-6.0.3.6/lib/active_record/migration.rb:890:in `block in method_missing'
/var/www/forum-lastapp/shared/bundle/ruby/2.6.0/gems/activerecord-6.0.3.6/lib/active_record/migration.rb:858:in `block in say_with_time'
/var/www/forum-lastapp/shared/bundle/ruby/2.6.0/gems/activerecord-6.0.3.6/lib/active_record/migration.rb:858:in `say_with_time'
以下省略

解決法

ローカルでデータベース関連の内容を修正した場合の対処が必要となる。

本番環境で以下二つのコマンドを実行する
% rails db:drop RAILS_ENV=production DISABLE_DATABASE_ENVIRONMENT_CHECK=1
% rails db:create RAILS_ENV=production

その後、一度プロセスをkillした上で「bundle exec cap production deploy」を実行すると、エラーは解決された。

0
0
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
0
0