开发者

How to migrate a boolean field in MySQL to PostgreSQL in Heroku?

开发者 https://www.devze.com 2023-03-29 22:20 出处:网络
I have a application, running with MySQL in my local machine. There is a field I define as boolean in Rails,开发者_C百科 which is represent in 0 or 1 in MySQL.

I have a application, running with MySQL in my local machine. There is a field I define as boolean in Rails,开发者_C百科 which is represent in 0 or 1 in MySQL.

I am now trying migrate to Heroku, which is using PostgreSQL. After push the code and database to Heroku, the app cannot run.

There is an error message.

ActiveRecord::StatementInvalid (PGError: ERROR:  operator does not exist: boolean = integer

How can I fix it?

Thanks all.


That's because MySQL uses TinyInt(1) for storing boolean attributes where as PostgreSQL has a native boolean type.

It's better to use a migration tool like

https://github.com/maxlapshin/mysql2postgres

which takes care of handling these problems.

Setup a local postgres database. Migrate from MySQL to your local Postgres DB. Then push from your local postgres DB to Heroku using taps.

Also, make sure you have not used 'y' or 'n' anywhere in the code, since these values are specific to MySQL

UPDATE: Before you do any of the above, check out this http://devcenter.heroku.com/articles/database#common_issues_migrating_to_postgresql

0

精彩评论

暂无评论...
验证码 换一张
取 消