【问题标题】:rails DB heroku migration error after column drop列删除后rails DB heroku迁移错误
【发布时间】:2017-08-03 05:54:33
【问题描述】:

删除列“类型”后,我无法在 Heroku 应用上迁移数据库

class RemoveTypeFromMandats < ActiveRecord::Migration[5.0]
def change
remove_column :mandats, :type, :boolean
end
end

我删除了这个专栏,因为我的名字弄错了, 列不能命名为“类型”

但是现在当我尝试在 heroku 上迁移我的数据库时,我遇到了这个错误

D, [2017-03-13T08:39:10.619658 #4] DEBUG -- :    (3.9ms)  ALTER TABLE      "mandats" DROP "type"
D, [2017-03-13T08:39:10.623526 #4] DEBUG -- :    (3.5ms)  ROLLBACK
D, [2017-03-13T08:39:10.627178 #4] DEBUG -- :    (3.3ms)  SELECT   pg_advisory_unlock(157042690317842070)
rails aborted!
StandardError: An error has occurred, this and all later migrations  canceled:

PG::UndefinedColumn: ERROR:  column "type" of relation "mandats" does not exist
: ALTER TABLE "mandats" DROP "type"

【问题讨论】:

  • 没有像 type 这样的列存在名称,您运行了该列的 remove_column
  • 所以我必须删除迁移?
  • column_exists? you 可以用于该迁移

标签: ruby-on-rails ruby postgresql heroku database-migration


【解决方案1】:

你可以试试column_exists?

class RemoveTypeFromMandats < ActiveRecord::Migration[5.0]
  def change
    if column_exists? :mandats, :type         
      remove_column :mandats, :type, :boolean
    end
  end
end

【讨论】:

    猜你喜欢
    • 2015-04-04
    • 1970-01-01
    • 2011-04-30
    • 2012-06-16
    • 2012-12-09
    • 2018-05-30
    • 2012-11-11
    • 2011-02-17
    • 1970-01-01
    相关资源
    最近更新 更多