Using BigInt - Rails 5.0.3

Viewed 865

I recently generated migrations to migrate my foreign keys to big ints on our Rails application, but I receive the following error when loading the application.

ActiveRecord::StatementInvalid (Mysql2::Error: Field 'id' doesn't have a default value

Any ideas as to why I'm getting this error? I was following this blog post about the new Rails convention - http://www.mccartie.com/2016/12/05/rails-5.1.html

Sample migration:

class ChangePrimaryKeyToBigintOnOrganizations < ActiveRecord::Migration[5.0]
  def change
    change_column :organizations, :id, :bigint
  end
end
1 Answers

The column's auto_increment attribute isn't preserved when changing the column type so you'll need to do it yourself:

change_column :organizations, :id, :bigint, auto_increment: true
Related