【发布时间】:2018-04-29 15:04:58
【问题描述】:
我像这样更改了数据库中的一列:
class ChangePriceToBeFloatInProducts < ActiveRecord::Migration[5.1]
def change
change_column :products, :price, :float
end
end
它在我的本地机器上运行良好,但每当我尝试通过 heroku run rake db:migrate 在 Heroku 上运行此迁移时,我都会收到以下错误:
StandardError: An error has occurred, this and all later migrations canceled:
PG::DatatypeMismatch: ERROR: column "price" cannot be cast automatically to type double precision
HINT: You might need to specify "USING price::double precision".
: ALTER TABLE "products" ALTER COLUMN "price" TYPE float
我已经尝试重置我的数据库,但我仍然收到同样的错误。
我该如何解决这个问题?
【问题讨论】:
-
该错误看起来像是来自 PostgreSQL。您是否还在您的开发机器上使用 PostgreSQL 数据库,或者您是否在使用其他东西(例如 SQLite、MariaDB 等)?
-
@Chris 我还是个新手,但我在终端上检查了一下,显然我正在使用 MySQL
-
您似乎在 Heroku 上使用 PostgreSQL,这是默认设置。您也应该考虑在本地安装它,让您的开发环境更接近生产环境。如果你在 OSX 上,postgresapp.com 是一个非常简单的方式来开始 Postrges。
标签: ruby-on-rails database heroku