【发布时间】:2016-08-31 22:52:31
【问题描述】:
我从 sqlite 迁移到 Postgres,所以我可以推送到 Heroku,并在运行 $ heroku run rake db:migrate: 时收到错误:
ActiveRecord::SchemaMigration Load (0.9ms) SELECT "schema_migrations".* FROM "schema_migrations"
Migrating to ChangeCheckIn (20160726015859)
(0.7ms) BEGIN
== 20160726015859 ChangeCheckIn: migrating ====================================
-- change_column(:listings, :check_in_date, :date)
(1.3ms) ALTER TABLE "listings" ALTER COLUMN "check_in_date" TYPE date
(0.7ms) ROLLBACK
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
PG::DatatypeMismatch: ERROR: column "check_in_date" cannot be cast automatically to type date
HINT: You might need to specify "USING check_in_date::date".
: ALTER TABLE "listings" ALTER COLUMN "check_in_date" TYPE date
当我最初为 :listing 构建模型时,check_in_date 是 type:date,但我通过迁移到字符串将其更改,并且在模式中它当前是字符串。下面的错误是在我将其更改为字符串之前引用了初始迁移和旧数据类型。
然后我根据这个关于 SO 的问题创建了一个新的迁移(下)并收到了一个新错误(下):Rails migrations - change_column with type conversion
change_column :listings, :check_in_date, 'string USING CAST(check_in_date AS string)'
PG::UndefinedObject: ERROR: type "string" does not exist
我在这里做错了什么?
【问题讨论】:
标签: ruby-on-rails postgresql ruby-on-rails-4 heroku rails-activerecord