在删除我的专栏“type”
之后,我在我的heroku应用上迁移数据库时遇到问题class RemoveTypeFromMandats < ActiveRecord::Migration[5.0]
def change
remove_column :mandats, :type, :boolean
end
end
我放弃了这个专栏,因为我的名字错了, 列不能命名为“type”
但是现在当我尝试在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"
答案 0 :(得分:0)
您可以尝试column_exists?
class RemoveTypeFromMandats < ActiveRecord::Migration[5.0]
def change
if column_exists? :mandats, :type
remove_column :mandats, :type, :boolean
end
end
end