我有2个表Manufacturer和TabsTemplate。这两个表使用多对多关联进行关联。但是,在服务器上运行应用程序时出现错误。
迁移-ManufacturerTabs
return queryInterface.createTable('ManufacturerTabs', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
},
ManufacturerId: {
type: Sequelize.INTEGER,
allowNull: false,
onDelete: 'CASCADE',
references: {
model: 'Manufacturers',
key: 'id'
}
},
TabsTemplateId: {
type: Sequelize.INTEGER,
allowNull: false,
onDelete: 'CASCADE',
references: {
model: 'TabsTemplates',
key: 'id'
}
}
});
型号-制造商
Manufacturer.associate = function (models) {
Manufacturer.belongsToMany(models.TabsTemplate, { through: ManufacturerTab});
};
模型-TabsTemplate
TabsTemplate.associate = function(models) {
TabsTemplate.belongsToMany(models.Manufacturer, { through: ManufacturerTab});
};
错误
warning ../../../../../../package.json: No license field
$ cross-env DEBUG=express-sequelize node ./bin/www nodemon app.js
sequelize deprecated String based operators are now deprecated. Please use Symbol based operators for better security, read more at http://docs.sequelizejs.com/manual/tutorial/querying.html#operators node_modules/sequelize/lib/sequelize.js:242:13
/Users/rdagli/Desktop/Projects/Internal/Brand Compass/Production/postgres-server/node_modules/sequelize/lib/associations/belongs-to-many.js:266
if (!this.through.model.rawAttributes[this.foreignKey]) {
^
TypeError: Cannot read property 'TabsTemplateId' of undefined
at BelongsToMany.injectAttributes (/Users/rdagli/Desktop/Projects/Internal/Brand Compass/Production/postgres-server/node_modules/sequelize/lib/associations/belongs-to-many.js:266:42)
at Function.belongsToMany (/Users/rdagli/Desktop/Projects/Internal/Brand Compass/Production/postgres-server/node_modules/sequelize/lib/associations/mixin.js:53:17)
at Function.TabsTemplate.associate (/Users/rdagli/Desktop/Projects/Internal/Brand Compass/Production/postgres-server/models/tabstemplate.js:13:18)
at Object.keys.forEach.modelName (/Users/rdagli/Desktop/Projects/Internal/Brand Compass/Production/postgres-server/models/index.js:29:19)
at Array.forEach (<anonymous>)
at Object.<anonymous> (/Users/rdagli/Desktop/Projects/Internal/Brand Compass/Production/postgres-server/models/index.js:27:17)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/rdagli/Desktop/Projects/Internal/Brand Compass/Production/postgres-server/routes/index.js:1:77)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/rdagli/Desktop/Projects/Internal/Brand Compass/Production/postgres-server/app.js:9:14)
error An unexpected error occurred: "Command failed.