一直试图解决这个问题,但到目前为止还没有运气。
尝试运行迁移时,出现以下错误;
== 20170904085107-kognitio-queue: migrating =======
TypeError: Cannot read property 'toString' of undefined
at Object.attributeToSQL (/home/vagrant/insights-api/node_modules/sequelize/lib/dialects/mysql/query-generator.js:240:34)
at Object.attributesToSQL (/home/vagrant/insights-api/node_modules/sequelize/lib/dialects/mysql/query-generator.js:306:45)
at QueryInterface.createTable (/home/vagrant/insights-api/node_modules/sequelize/lib/query-interface.js:171:38)
at Object.up (/home/vagrant/insights-api/lib/migrations/20170904085107-kognitio-queue.js:4:31)
at constructor._exec (/home/vagrant/insights-api/node_modules/umzug/lib/migration.js:104:23)
at constructor.up (/home/vagrant/insights-api/node_modules/umzug/lib/migration.js:69:17)
at constructor.<anonymous> (/home/vagrant/insights-api/node_modules/umzug/index.js:124:28)
at PassThroughHandlerContext.finallyHandler (/home/vagrant/insights-api/node_modules/bluebird/js/release/finally.js:57:23)
at PassThroughHandlerContext.tryCatcher (/home/vagrant/insights-api/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/home/vagrant/insights-api/node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (/home/vagrant/insights-api/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromise0 (/home/vagrant/insights-api/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/home/vagrant/insights-api/node_modules/bluebird/js/release/promise.js:693:18)
at Promise._fulfill (/home/vagrant/insights-api/node_modules/bluebird/js/release/promise.js:638:18)
at Promise._resolveCallback (/home/vagrant/insights-api/node_modules/bluebird/js/release/promise.js:432:57)
at Promise._settlePromiseFromHandler (/home/vagrant/insights-api/node_modules/bluebird/js/release/promise.js:524:17)
迁移文件如下;
'use strict';
module.exports = {
up: function(queryInterface, Sequelize) {
return queryInterface.createTable('Kognitio_Queue', {
queue_id: {
allowNull: false,
primaryKey: true,
type: Sequelize.INTEGER
},
queue_user: {
allowNull: false,
type: Sequelize.STRING(20)
},
queue_query: {
allowNull: false,
type: Sequelize.LONG
},
queue_added: {
allowNull: false,
type: Sequelize.DATETIME,
defaultValue: Sequelize.NOW
},
queue_executed: {
allowNull: true,
type: Sequelize.DATETIME
},
queue_save_results: {
allowNull: false,
type: Sequelize.BOOLEAN
},
queue_results_path: {
allowNull: true,
type: Sequelize.TEXT
}
});
},
down: function(queryInterface, Sequelize) {
return queryInterface.dropTable('Kognitio_Queue');
}
};
我的模型文件是;
module.exports = (sequelize, DataTypes) => {
const Kognitio_Queue = sequelize.define('Kognitio_Queue', {
queue_id: {
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
},
queue_user: {
type: DataTypes.STRING(20),
allowNull: false
},
queue_query: {
allowNull: false,
type: DataTypes.LONG
},
queue_added: {
allowNull: false,
type: DataTypes.DATETIME
},
queue_executed: {
allowNull: true,
type: DataTypes.DATETIME
},
queue_save_results: {
allowNull: false,
type: DataTypes.BOOLEAN
},
queue_results_path: {
allowNull: true,
type: DataTypes.TEXT
}
}, {
underscored: true,
freezeTableName: true
});
return Kognitio_Queue;
};
我对可能导致此错误发生的原因感到茫然,因为我已检查这些文件与其他成功运行的迁移,并且看不出它们之间的差异。我已经彻底清除了整个数据库并重新启动,但这是唯一失败的数据库。
提前致谢
答案 0 :(得分:14)
弄清楚它是无法识别的数据类型。
答案 1 :(得分:3)
将 DATETIME 更改为 DATE ,续集中没有名为DATETIME的数据类型。 DATE与DATETIME相同,而DATEONLY与DATE类似 详细信息:http://docs.sequelizejs.com/variable/index.html
答案 2 :(得分:3)
请确保使用大写数据类型:
使用DATE代替日期或日期