PG::DatatypeMismatch: ERROR: column "status" cannot be cast automatically to type integer

Viewed 3216

i used sqlite3 for in development but i am getting error in while PostgreSQL migration

such error is not found in sqlite migration of database.

error-log

PG::DatatypeMismatch: ERROR:  column "status" cannot be cast automatically to type integer

HINT:  You might need to specify "USING status::integer".
/home/abc/abc/db/migrate/20200211044313_change_status_type_in_stages.rb:3:in `change'

20200113224031_create_stages.rb

class CreateStages < ActiveRecord::Migration[5.2]
  def change
    create_table :stages do |t|
      t.string :stage
      t.boolean :status

      t.timestamps
    end
  end
end

db/20200211044313_change_status_type_in_stages.rb

  def change
    change_column :stages, :status, :integer
  end
1 Answers

You need to specify how data should be converted.

  change_column :stages, :status, 'integer USING CAST(status AS integer)'

OR

  change_column :stages, :status, :integer, using: 'status::integer'

Changing the Column Type - Errors

Related