【音声ファイルアップロード機能】migrationで型(タイプ)変更してuser_idを外部キーとする(できない)

2021/08/01に公開

https://e-words.jp/w/外部キー制約.html

https://readouble.com/laravel/6.x/ja/migrations.html?header=%25E3%2583%2587%25E3%2583%2595%25E3%2582%25A9%25E3%2583%25AB%25E3%2583%2588Expression

Note: 以降のカラムタイプのみ変更可能です:bigInteger、binary、boolean、date、dateTime、dateTimeTz、decimal、integer、json、longText、mediumText、smallInteger、string、text、time、unsignedBigInteger、unsignedInteger and unsignedSmallInteger

カラムの変更では外部キーを作れない
よって既存のものを削除して、新しく外部キーとしてuser_idカラムを作成する必要がある

以下の流れで行う

  • musicfilesのuseridカラム削除
  • 外部キーとしてuseridカラム追加

Discussion