質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
86.12%
Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

解決済

テーブルが作成されません

退会済みユーザー

退会済みユーザー

総合スコア0

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

2回答

0リアクション

0クリップ

303閲覧

投稿2022/09/28 01:42

編集2022/09/28 04:04

rails db:migrate実行後

フォロー機能作成の為、rails db:migrateをコマンド入力をしたのですが、テーブルが作成されずエラーが発生してしまいました。
エラーの原因が調べてもよく分からず困っています。
見て頂けないでしょうか?

エラー

Running via Spring preloader in process 4973 == 20220928013253 CreateRelationships: migrating ============================== -- create_table(:relationships) rake aborted! StandardError: An error has occurred, all later migrations canceled: Column `user_id` on table `relationships` does not match column `id` on `users`, which has type `bigint(20)`. To resolve this issue, change the type of the `user_id` column on `relationships` to be :bigint. (For example `t.bigint :user_id`). Original message: Mysql2::Error: Cannot add foreign key constraint /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/mysql2-0.5.4/lib/mysql2/client.rb:148:in `_query' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/mysql2-0.5.4/lib/mysql2/client.rb:148:in `block in query' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/mysql2-0.5.4/lib/mysql2/client.rb:147:in `handle_interrupt' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/mysql2-0.5.4/lib/mysql2/client.rb:147:in `query' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:206:in `block (2 levels) in execute' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:205:in `block in execute' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract_adapter.rb:696:in `block (2 levels) in log' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract_adapter.rb:695:in `block in log' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/notifications/instrumenter.rb:24:in `instrument' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract_adapter.rb:687:in `log' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:204:in `execute' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/mysql/database_statements.rb:52:in `execute' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/schema_statements.rb:322:in `create_table' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/mysql/schema_statements.rb:81:in `create_table' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:929:in `block in method_missing' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:897:in `block in say_with_time' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:897:in `say_with_time' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:918:in `method_missing' /home/ubuntu/environment/tsunageru/db/migrate/20220928013253_create_relationships.rb:3:in `change' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:867:in `exec_migration' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:851:in `block (2 levels) in migrate' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:850:in `block in migrate' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:462:in `with_connection' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:849:in `migrate' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:1037:in `migrate' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:1329:in `block in execute_migration_in_transaction' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:1382:in `ddl_transaction' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:1328:in `execute_migration_in_transaction' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:1302:in `each' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:1302:in `migrate_without_lock' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:1251:in `block in migrate' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:1401:in `block in with_advisory_lock' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:1416:in `block in with_advisory_lock_connection' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:462:in `with_connection' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:1416:in `with_advisory_lock_connection' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:1397:in `with_advisory_lock' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:1251:in `migrate' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:1086:in `up' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:1061:in `migrate' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/tasks/database_tasks.rb:237:in `migrate' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/railties/databases.rake:92:in `block (3 levels) in <main>' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/railties/databases.rake:90:in `each' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/railties/databases.rake:90:in `block (2 levels) in <main>' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/fork_tracker.rb:10:in `block in fork' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/fork_tracker.rb:10:in `block in fork' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/fork_tracker.rb:8:in `fork' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/fork_tracker.rb:8:in `fork' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/fork_tracker.rb:27:in `fork' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/fork_tracker.rb:8:in `fork' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/fork_tracker.rb:27:in `fork' <internal:/home/ubuntu/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require' <internal:/home/ubuntu/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require' -e:1:in `<main>' Caused by: ActiveRecord::MismatchedForeignKey: Column `user_id` on table `relationships` does not match column `id` on `users`, which has type `bigint(20)`. To resolve this issue, change the type of the `user_id` column on `relationships` to be :bigint. (For example `t.bigint :user_id`). Original message: Mysql2::Error: Cannot add foreign key constraint /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/mysql2-0.5.4/lib/mysql2/client.rb:148:in `_query' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/mysql2-0.5.4/lib/mysql2/client.rb:148:in `block in query'           ・           ・           ・ Caused by: Mysql2::Error: Cannot add foreign key constraint      ・      ・      ・ Tasks: TOP => db:migrate (See full trace by running task with --trace)

マイグレーションファイル

class CreateRelationships < ActiveRecord::Migration[6.1] def change create_table :relationships do |t| t.references :user, null: false, foreign_key: true t.references :follow, null: false, foreign_key: true t.timestamps t.index [:user_id, :follow_id], unique: true end end end

文字数制限で質問ができなかったため、重要だと思われる個所だけを残しました。
必要とされる個所は、追記したいと思います。

!追記
恐らく、user_idに関することだと思うのですが、カラムのデータ型に関して言っているのでしょうか?
0
!追記
>マイグレーションファイルの作成順は、参照されるテーブルが先になっていますか?
イメージ説明
参照されるテーブルというのはrelationshipsのことですか?

以下のような質問にはリアクションをつけましょう

  • 質問内容が明確
  • 自分も答えを知りたい
  • 質問者以外のユーザにも役立つ

リアクションが多い質問は、TOPページの「注目」タブのフィードに表示されやすくなります。

気になる質問をクリップする

クリップした質問は、後からいつでもマイページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

下記のような質問は推奨されていません。

  • 間違っている
  • 質問になっていない投稿
  • スパムや攻撃的な表現を用いた投稿

適切な質問に修正を依頼しましょう。

退会済みユーザー

退会済みユーザー

2022/09/28 01:49

エラー全文 Running via Spring preloader in process 4973 == 20220928013253 CreateRelationships: migrating ============================== -- create_table(:relationships) rake aborted! StandardError: An error has occurred, all later migrations canceled: Column `user_id` on table `relationships` does not match column `id` on `users`, which has type `bigint(20)`. To resolve this issue, change the type of the `user_id` column on `relationships` to be :bigint. (For example `t.bigint :user_id`). Original message: Mysql2::Error: Cannot add foreign key constraint /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/mysql2-0.5.4/lib/mysql2/client.rb:148:in `_query' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/mysql2-0.5.4/lib/mysql2/client.rb:148:in `block in query' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/mysql2-0.5.4/lib/mysql2/client.rb:147:in `handle_interrupt' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/mysql2-0.5.4/lib/mysql2/client.rb:147:in `query' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:206:in `block (2 levels) in execute' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:205:in `block in execute' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract_adapter.rb:696:in `block (2 levels) in log' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract_adapter.rb:695:in `block in log' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/notifications/instrumenter.rb:24:in `instrument' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract_adapter.rb:687:in `log' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:204:in `execute' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/mysql/database_statements.rb:52:in `execute' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/schema_statements.rb:322:in `create_table' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/mysql/schema_statements.rb:81:in `create_table' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:929:in `block in method_missing' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:897:in `block in say_with_time' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:897:in `say_with_time' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:918:in `method_missing' /home/ubuntu/environment/tsunageru/db/migrate/20220928013253_create_relationships.rb:3:in `change' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:867:in `exec_migration' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:851:in `block (2 levels) in migrate' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:850:in `block in migrate' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:462:in `with_connection' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:849:in `migrate' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:1037:in `migrate' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:1329:in `block in execute_migration_in_transaction' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:1382:in `ddl_transaction' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:1328:in `execute_migration_in_transaction' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:1302:in `each' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:1302:in `migrate_without_lock' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:1251:in `block in migrate' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:1401:in `block in with_advisory_lock' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:1416:in `block in with_advisory_lock_connection' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:462:in `with_connection' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:1416:in `with_advisory_lock_connection' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:1397:in `with_advisory_lock' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:1251:in `migrate' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:1086:in `up' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/migration.rb:1061:in `migrate' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/tasks/database_tasks.rb:237:in `migrate' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/railties/databases.rake:92:in `block (3 levels) in <main>' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/railties/databases.rake:90:in `each' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/railties/databases.rake:90:in `block (2 levels) in <main>' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/fork_tracker.rb:10:in `block in fork' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/fork_tracker.rb:10:in `block in fork' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/fork_tracker.rb:8:in `fork' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/fork_tracker.rb:8:in `fork' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/fork_tracker.rb:27:in `fork' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/fork_tracker.rb:8:in `fork' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/fork_tracker.rb:27:in `fork' <internal:/home/ubuntu/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require' <internal:/home/ubuntu/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require' -e:1:in `<main>' Caused by: ActiveRecord::MismatchedForeignKey: Column `user_id` on table `relationships` does not match column `id` on `users`, which has type `bigint(20)`. To resolve this issue, change the type of the `user_id` column on `relationships` to be :bigint. (For example `t.bigint :user_id`). Original message: Mysql2::Error: Cannot add foreign key constraint /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/mysql2-0.5.4/lib/mysql2/client.rb:148:in `_query' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/mysql2-0.5.4/lib/mysql2/client.rb:148:in `block in query' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/mysql2-0.5.4/lib/mysql2/client.rb:147:in `handle_interrupt' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/mysql2-0.5.4/lib/mysql2/client.rb:147:in `query' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:206:in `block (2 levels) in execute' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:205:in `block in execute' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract_adapter.rb:696:in `block (2 levels) in log' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt' /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.7/lib/active_support/concurrency/loa

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
86.12%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問

同じタグがついた質問を見る

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。