satya
Fri Feb 23 2024
While changing a column type from one type to another and running
above error ^ because i was converting
so in order to fix this we have to mention the
#migration, #database, #rails
rails db:migrate
, it will throw the below error
PG::DatatypeMismatch: ERROR: column "tags" cannot be cast automatically to type jsonb
HINT: You might need to specify "USING tags::jsonb".
above error ^ because i was converting
tags
field from type string
to jsonb
so in order to fix this we have to mention the
USING tags::jsonb
and cast the type.
class ChangeTagsToJsonbInTils < ActiveRecord::Migration[7.0]
def change
change_column :tils, :tags, 'jsonb USING CAST(tags AS jsonb)'
end
end
#migration, #database, #rails