mnyon-grandkru / knowledgebase

An issue tracker of error messages discovered while developing as well as their solution.
https://github.com/mnyon-grandkru/knowledgebase/issues
MIT License
2 stars 0 forks source link

Error when changing Postgres column type to from integer to uuid #114

Closed mnyon-grandkru closed 1 year ago

mnyon-grandkru commented 1 year ago

I'm trying to convert a column in the table from integer to uuid.

When I use the following migration:

change_column: <table_name>, :gameId, :uuid

I get the following error:

ActiveRecord::StatementInvalid: PG::DatatypeMismatch: ERROR:  column "gameId" cannot be cast automatically to type uuid
HINT:  You might need to specify "USING "gameId"::uuid".

There may be a solution in the following StackOverflow link. I'll confirm shortly.

mnyon-grandkru commented 1 year ago

The solution to this is to drop the columns and recreate them with the desired column. That fixed the problem at hand.