错误:“name_id”列无法自动转换为整数类型您可能需要指定“USING name_id::integer”

问题描述 投票:0回答:1

我在将我的应用程序部署到 heroku 时经历了最艰难的时期。当我尝试运行

RAILS_ENV=production bundle exec rake db:migrate
时,我最终收到一条错误消息

PG::DatatypeMismatch: ERROR:  column "downtown_id" cannot be cast automatically to type integer
HINT:  You might need to specify "USING downtown_id::integer"

我尝试的第一件事是这个

  def change
      remove_column :properties, :downtown_id
      add_column :properties, :downtown_id, :integer
  end

运气不好。

然后我尝试了这个。 (从here找到)。

  def change
    change_column :properties, :downtown_id, 'integer USING CAST(downtown_id AS integer)'
  end

仍然没有运气。 :(

首先在我的开发环境中运行这些迁移之后,我需要做些什么才能尝试在

RAILS_ENV=production bundle exec rake db:migrate
上运行它们?

我不知道该怎么做,我所看到的一切都指向我已经尝试过的事情。

ruby-on-rails postgresql rails-migrations
1个回答
0
投票

尝试使用这个语法:

def change
  change_column :properties, :downtown_id, :integer, using: 'CAST(downtown_id AS integer)'
end
© www.soinside.com 2019 - 2024. All rights reserved.