マイグレーションファイルを作成したあと、db:migrateを実行したいのですがうまくいきません。
ruby
1$ docker-compose run --rm api bin/rails db:migrate 2Starting ***************_db_1 ... done 3== 20200813045222 CreateStaffs: migrating ===================================== 4-- create_table(:staffs) 5rails aborted! 6StandardError: An error has occurred, all later migrations canceled: 7 8Mysql2::Error: Table '***************_development.offices' doesn't exist 9 10Caused by: 11ActiveRecord::StatementInvalid: Mysql2::Error: Table '***************_development.offices' doesn't exist 12 13Caused by: 14Mysql2::Error: Table '***************_development.offices' doesn't exist 15/usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:131:in `_query' 16/usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:131:in `block in query' 17/usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:130:in `handle_interrupt' 18/usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:130:in `query' 19/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:201:in `block (2 levels) in execute' 20/usr/local/bundle/gems/activesupport-6.0.3.1/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads' 21/usr/local/bundle/gems/activesupport-6.0.3.1/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares' 22/usr/local/bundle/gems/activesupport-6.0.3.1/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads' 23/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:200:in `block in execute' 24/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract_adapter.rb:722:in `block (2 levels) in log' 25/usr/local/bundle/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize' 26/usr/local/bundle/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt' 27/usr/local/bundle/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize' 28/usr/local/bundle/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt' 29/usr/local/bundle/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize' 30/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract_adapter.rb:721:in `block in log' 31/usr/local/bundle/gems/activesupport-6.0.3.1/lib/active_support/notifications/instrumenter.rb:24:in `instrument' 32/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract_adapter.rb:712:in `log' 33/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:199:in `execute' 34/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/mysql/database_statements.rb:41:in `execute' 35/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:210:in `execute_and_free' 36/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:746:in `column_definitions' 37/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:114:in `columns' 38/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract_adapter.rb:745:in `column_for' 39/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:781:in `mismatched_foreign_key' 40/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:616:in `translate_exception' 41/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract_adapter.rb:704:in `translate_exception_class' 42/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract_adapter.rb:725:in `rescue in block in log' 43/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract_adapter.rb:721:in `block in log' 44/usr/local/bundle/gems/activesupport-6.0.3.1/lib/active_support/notifications/instrumenter.rb:24:in `instrument' 45/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract_adapter.rb:712:in `log' 46/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:199:in `execute' 47/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/mysql/database_statements.rb:41:in `execute' 48/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:315:in `create_table' 49/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/mysql/schema_statements.rb:81:in `create_table' 50/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:890:in `block in method_missing' 51/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:858:in `block in say_with_time' 52/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:858:in `say_with_time' 53/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:879:in `method_missing' 54/api/db/migrate/20200813045222_create_staffs.rb:3:in `change' 55/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:828:in `exec_migration' 56/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:812:in `block (2 levels) in migrate' 57/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:811:in `block in migrate' 58/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:471:in `with_connection' 59/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:810:in `migrate' 60/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:1002:in `migrate' 61/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:1310:in `block in execute_migration_in_transaction' 62/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:1363:in `ddl_transaction' 63/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:1309:in `execute_migration_in_transaction' 64/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:1281:in `block in migrate_without_lock' 65/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:1280:in `each' 66/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:1280:in `migrate_without_lock' 67/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:1229:in `block in migrate' 68/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:1382:in `with_advisory_lock' 69/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:1229:in `migrate' 70/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:1061:in `up' 71/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:1036:in `migrate' 72/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/tasks/database_tasks.rb:238:in `migrate' 73/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/railties/databases.rake:86:in `block (3 levels) in <main>' 74/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/railties/databases.rake:84:in `each' 75/usr/local/bundle/gems/activerecord-6.0.3.1/lib/active_record/railties/databases.rake:84:in `block (2 levels) in <main>' 76/usr/local/bundle/gems/railties-6.0.3.1/lib/rails/commands/rake/rake_command.rb:23:in `block in perform' 77/usr/local/bundle/gems/railties-6.0.3.1/lib/rails/commands/rake/rake_command.rb:20:in `perform' 78/usr/local/bundle/gems/railties-6.0.3.1/lib/rails/command.rb:48:in `invoke' 79/usr/local/bundle/gems/railties-6.0.3.1/lib/rails/commands.rb:18:in `<main>' 80/usr/local/bundle/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require' 81/usr/local/bundle/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi' 82/usr/local/bundle/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register' 83/usr/local/bundle/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi' 84/usr/local/bundle/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require' 85/usr/local/bundle/gems/activesupport-6.0.3.1/lib/active_support/dependencies.rb:324:in `block in require' 86/usr/local/bundle/gems/activesupport-6.0.3.1/lib/active_support/dependencies.rb:291:in `load_dependency' 87/usr/local/bundle/gems/activesupport-6.0.3.1/lib/active_support/dependencies.rb:324:in `require' 88bin/rails:4:in `<main>' 89 90Caused by: 91Mysql2::Error: Cannot add foreign key constraint 92 93Tasks: TOP => db:migrate 94(See full trace by running task with --trace)
どうかいけつすればよいのでしょうか。
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/08/26 02:57
2020/08/26 03:13