PG :: DatatypeMismatch error when doing heroku run rails db: migrate

error contents

PG::DatatypeMismatch: ERROR: default for column "complete" cannot be cast automatically to type integer

I was told that the complete column cannot be automatically converted to an integer.

The cause is


 def up
    change_column :habits, :complete, :integer, using: 'complete :: integer'
  end

  def down
    change_column :habits, :complete, :boolean, default: false, null: false
  end
end

I changed from boolean to integer type in change_column, but an error occurred because I tried to change to integer while default was false in the complte column.

So delete the false data in the complte column and rails db: migrate: reset

This is a safe solution

Recommended Posts

PG :: DatatypeMismatch error when doing heroku run rails db: migrate
[heroku] run rails db: migrate doesn't work
Error in rails db: migrate
[Rails] "private method` String' called ~ "error when db: migrate
After all, what is [rails db: migrate] doing?
rails db: migrate failed!
Error with db: migrate: reset
Error when using rails capybara
When I run rails: db: migrate, I get "Directly inheriting from ActiveRecord :: Migration is not supported."
[Rails] What to do when the error No database selected and Unknown database appears in db: migrate
DB error on deploying with Heroku
[Rails] Modify migrate file (rails db: rollback)
[Rails] Modify migrate file (rails db: rollback STEP =)
Error when trying to use heroku command
[Rails / Heroku] Error resolution procedure after push
What to do if you get an error on heroku rake db: migrate