2
定義模型時,我有一個續集DataTypes.INTEGER問題。我在電子書中以「使用Node.js構建API」爲例。我是一個試圖抓住快遞和續集的新手。任何幫助非常感謝。謝謝。sequelize DataTypes TypeError:無法讀取未定義的屬性'INTEGER'
錯誤的詳細信息:
> /home/xxx/workspace/ntask-api/models/tasks.js:9
> type: DataTypes.INTEGER,
> ^TypeError: Cannot read property 'INTEGER' of undefined
> at Function.module.exports (/home/xxx/workspace/ntask-api/models/tasks.js:9:21)
> at Consign.into (/home/xxx/workspace/ntask-api/node_modules/consign/lib/consign.js:239:17)
> at Object.<anonymous> (/home/xxx/workspace/ntask-api/index.js:13:5)
> at Module._compile (module.js:456:26)
> at Object.Module._extensions..js (module.js:474:10)
> at Module.load (module.js:356:32)
> at Function.Module._load (module.js:312:12)
> at Function.Module.runMain (module.js:497:10)
> at startup (node.js:119:16)
> at node.js:902:3
下面的代碼樣本中
/models/tasks.js
:
> module.exports = function(sequelize, DataTypes){
> //console.log(DataTypes.INTEGER);
> const Tasks = sequelize.define("Tasks", { id: {
> type: DataTypes.INTEGER,
> primaryKey: true,
> autoIncrement: true }, title: {
> type: DataTypes.STRING,
> allowNull: false,
> validate: { notEmpty: true
> } }, done: {
> type: DataTypes.BOOLEAN,
> allowNull: false,
> defaultValue: false }
> },
> { classMethods:{
> associate: function(models){ Tasks.belongsTo(models.Users, {
> onDelete: "CASCADE",
> foreignKey: { allowNull: false
> } });
> } }
> });
> return Tasks; };
我也加入這模型/任務上試圖從TypeError: object is not a function when defining models in NodeJs using Sequelize建議.js文件,但同樣的錯誤。
var DataTypes = require('sequelize/lib/data-types');
感謝@hiEven,會嘗試一下。 – luhfluh
它像一個魅力工作! ...只是堅持1,但會在稍後嘗試2。再次感謝。 – luhfluh