lml/commontator

Upgrade from 5.1.0 - migrate issue 'Column `parent_id` on table `commontator_comments` does not match column `id` on '

Closed this issue · 3 comments

After updating to 6.0.1 from 5.1.0, I run the following and hit this wall:

rake commontator:install
Copied migration 20190904222732_add_replying_to_comments.commontator.rb from commontator

rake db:migrate
== 20190904222732 AddReplyingToComments: migrating ============================
-- add_reference(:commontator_comments, :parent, {:foreign_key=>{:to_table=>:commontator_comments, :on_update=>:restrict, :on_delete=>:cascade}})
rake aborted!
StandardError: An error has occurred, all later migrations canceled:

Column parent_id on table commontator_comments does not match column id on commontator_comments, which has type int(11). To resolve this issue, change the type of the parent_id column on commontator_comments to be :integer. (For example t.integer :parent_id).
Original message: Mysql2::Error: Cannot add foreign key constraint

This is a common rails/mysql issue. I believe it's the reason they started labeling migrations with the rails version. I think the easiest way to solve this is to change the new commontator migration to have the same rails version (in the square brackets) as the old migration.

I'm referring to the square brackets on this line: https://github.com/lml/commontator/blob/master/db/migrate/1_add_replying_to_comments.rb#L1

A different way that should also work would be to change the type of the commontator_comments id column to bigint, which is the new default since Rails 5.1: rails/rails#26266

This worked. Thank you.