当尝试撤消heroku-postgres数据库中的迁移迁移时,由于ENUM类型不存在,我得到了SequelizeDatabaseError
。
我有几个具有ENUM数据类型的表/模型。在向下迁移中,我尝试删除表,然后也删除表的关联枚举数据类型。到目前为止,似乎只能在两个方向上正确应用一次迁移。
我尝试手动删除每种类型,然后全部迁移,然后全部撤消,但是在同一模型上总是失败,说ENUM类型不存在(显然是在向上迁移中创建的)。
这是一个迁移失败的模型。
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('PatientContacts', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
phoneHome: {
type: Sequelize.STRING,
allowNull: true,
},
phoneWork: {
type: Sequelize.STRING,
allowNull: true,
},
phoneMobile: {
type: Sequelize.STRING,
allowNull: false,
},
phonePreferred: {
type: Sequelize.ENUM,
values: ['Home','Work','Mobile', null]
},
smsNotifications: {
type: Sequelize.ENUM,
values: [true, false, null]
},
email: {
type: Sequelize.STRING,
allowNull: true,
},
emailConsent: {
type: Sequelize.ENUM,
values: [true, false, null]
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('PatientContacts')
.then(() => queryInterface.sequelize.query('DROP TYPE "public"."enum_PatientContacts_emailConsent;"'))
.then(() => queryInterface.sequelize.query('DROP TYPE "public"."enum_PatientContacts_phonePreferred;"'))
.then(() => queryInterface.sequelize.query('DROP TYPE "public"."enum_PatientContacts_smsNotifications;"'))
.catch(err => {
console.log(err);
throw new Error(err);
})
}
};
我希望向下迁移可以在回调中执行原始查询。但是,该错误如上所述。
Error: SequelizeDatabaseError: type "public.enum_PatientContacts_emailConsent;" does not exist
at queryInterface.dropTable.then.then.then.catch.err (/app/migrations/20181213023202-create-PatientContact.js:56:13)
at tryCatcher (/app/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/app/node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (/app/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromise0 (/app/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/app/node_modules/bluebird/js/release/promise.js:690:18)
at _drainQueueStep (/app/node_modules/bluebird/js/release/async.js:138:12)
at _drainQueue (/app/node_modules/bluebird/js/release/async.js:131:9)
at Async._drainQueues (/app/node_modules/bluebird/js/release/async.js:147:5)
at Immediate.Async.drainQueues [as _onImmediate] (/app/node_modules/bluebird/js/release/async.js:17:14)
at runCallback (timers.js:693:18)
at tryOnImmediate (timers.js:664:5)
at processImmediate (timers.js:646:5)
我应该提到,在我的最新尝试中,以“ public”作为类型名称的前缀。删除它也会产生相同的结果。
答案 0 :(得分:0)
对于这个问题困扰了几个小时,我感到非常失望。
用分号结束原始查询的目的是在双引号之后键入类型名称,但在单引号之前结束整个sql查询本身。