前提
rubyで自主制作のアプリ開発をしており、ローカル環境である程度動作確認を終えて一度Herokuへデプロイをしようとしています。
実現したいこと
herokuへのマイグレーション
発生している問題・エラーメッセージ
heroku run rails db:migrateを実行するとターミナルで以下のエラーが発生。
ステータスを確認すると、usersテーブルとmainroomsテーブルはupの状態で、中間テーブルのuser_mainroomsテーブルがうまくマイグレーションできない。
恐らくエラー文としてはmainroomsテーブルが無いと言われている。
Mysql2::Error: Table 'heroku_5ac2202ae42197e.mainrooms' doesn't exist
ActiveRecord::StatementInvalid: Mysql2::Error: Table 'heroku_5ac2202ae42197e.mainrooms' doesn't exist
Mysql2::Error: Cannot add foreign key constraint
ソースコード
mainrooms.rb
1class CreateMainrooms < ActiveRecord::Migration[6.0] 2 def change 3 create_table :mainrooms do |t| 4 t.string :name, null: false 5 t.timestamps 6 end 7 end 8end
user_mainrooms.rb
1class CreateUserMainrooms < ActiveRecord::Migration[6.0] 2 def change 3 create_table :user_mainrooms do |t| 4 t.references :mainroom, null: false, foreign_key: true 5 t.references :user, null: false, foreign_key: true 6 t.timestamps 7 end 8 end 9end
routes.rb
1Rails.application.routes.draw do 2 devise_for :users 3 root to: "mainrooms#index" 4 resources :users, only: [:edit, :update, :show] 5 resources :mainrooms, only: [:new, :create] 6end
試したこと
デプロイを最初のほうで忘れていて3つのテーブルが完成してからデプロイしてしまったのがよくなかったのかと考えましたが知識が浅く、インターネットで検索をかけましたが自分がどの状態にあたるのかわからず止まってしまっています。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。