简体   繁体   English

如何将MySQL中的布尔值字段迁移到Heroku中的PostgreSQL?

[英]How to migrate a boolean field in MySQL to PostgreSQL in Heroku?

I have a application, running with MySQL in my local machine. 我有一个在本地计算机上运行MySQL的应用程序。 There is a field I define as boolean in Rails, which is represent in 0 or 1 in MySQL. 我在Rails中定义了一个布尔值字段,在MySQL中用0或1表示。

I am now trying migrate to Heroku, which is using PostgreSQL. 我现在正在尝试迁移到使用PostgreSQL的Heroku。 After push the code and database to Heroku, the app cannot run. 将代码和数据库推送到Heroku后,该应用程序将无法运行。

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. 这是因为MySQL使用TinyInt(1)来存储布尔属性,而PostgreSQL具有本机布尔类型。

It's better to use a migration tool like 最好使用类似

https://github.com/maxlapshin/mysql2postgres https://github.com/maxlapshin/mysql2postgres

which takes care of handling these problems. 负责处理这些问题。

Setup a local postgres database. 设置本地postgres数据库。 Migrate from MySQL to your local Postgres DB. 从MySQL迁移到本地Postgres DB。 Then push from your local postgres DB to Heroku using taps. 然后使用水龙头将本地Postgres数据库推送到Heroku。

Also, make sure you have not used 'y' or 'n' anywhere in the code, since these values are specific to MySQL 另外,请确保您未在​​代码中的任何地方使用“ y”或“ n”,因为这些值特定于MySQL

UPDATE: Before you do any of the above, check out this http://devcenter.heroku.com/articles/database#common_issues_migrating_to_postgresql 更新:在执行上述任何操作之前,请查看此http://devcenter.heroku.com/articles/database#common_issues_migrating_to_postgresql

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM