我正在尝试执行后续迁移以更改“tweet”模型表中的“number”列
class ChangeDataTypeForTweetsNumber < ActiveRecord::Migration
def up
change_column :tweets do |t|
t.change :number, :integer
end
end
def down
change_table :tweets do |t|
t.change :number, :string
end
end
end
在执行后续迁移到 heroku 后......
heroku rake db:migrate:up VERSION=20120925211232
出现以下错误
PG::Error: ERROR: column "number" cannot be cast to type integer
: ALTER TABLE "tweets" ALTER COLUMN "number" TYPE integer
如果您有任何想法,我们将不胜感激。
谢谢大家
最佳答案
同上但更简洁一点:
change_column :yourtable, :column_to_change, 'integer USING CAST("column_to_change" AS integer)'
关于ruby-on-rails - 推送到 Heroku 时带有 Postgres 的 Rails 迁移错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12603498/