Skip to content

PG::DatatypeMismatch - Cant change columns data type from boolean to integer #61

Description

@oliverochman

Problem

When I try to change a columns data type from boolean to integer I get an error from postgres about how the column cant automatically be cast to the type of integer.

Background

I have a model with the name Inquiry that has a column named flexible regarding if the person needs to have a flexible office situation or not. Initially it was a true/false, but with input from the client we now need to be able to have both as an option. Therefor I created a migration to change the data type of that column from boolean to integer so I can make use of enums to solve that issue.

Implementation code

This is how the migration file looks like

class ChangeDataTypeForFlexible < ActiveRecord::Migration[6.1]
  def change
    change_column :inquiries, :flexible, :integer
  end
end

Screenshots

Screenshot from 2021-06-15 11-41-51

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions