Rails 6.1.5でdb:migrationのときにreference周りでエラー

Ruby on Rails

問題

rails db:migrateをしたときに、以下のようなエラーが出るようになってしまった。

親のキーがbigntで作られていないから、外部キーが貼れないというエラー。

Column `parent_id` on table `children` does not match column `id` on `parents`, which has type `bigint`. To resolve this issue, change the type of the `parent_id` column on `parents` to be :bigint. (For example `t.bigint :parent_id`).
Original message: Mysql2::Error: Referencing column 'parent_id' and referenced column 'id' in foreign key constraint 'fk_rails_0525da88a4' are incompatible.

調査

しかしながら、show create table parents; してみたら、親のカラムはbigintで作られている。。。

rails 6.1.6に上げたら発生しなくなりました。rails 6.1.5に戻したら再現性あります。

rails 6.1.6のchangelogを見てもそれらしき記述はなかったです。謎です。

migrationのファイルはすべて6.0以降です。

以下の結果は何も無いことを確認。

% git grep ActiveRecord::Migration db |grep -v 6.0|grep -v 6.1

考察

面倒なので原因は深追いしてない。。。

コメント