0
最新の変更が確実に反映されるように、強制的に同期させながら、製品モデルとユーザーモデルを関連付けることを試みています。列UserIdとProductManagerIdが作成されないというエラーが表示されます。Sequelize Association Columnsが生成されません
なぜ列が自動生成されないのですか?
Product.js
'use strict';
/* Model ONLY for DePuy Products */
module.exports = function(sequelize, DataTypes) {
var Product = sequelize.define('Product', {
name: {
type: DataTypes.STRING,
allowNull : false
},
sku: {
type:DataTypes.STRING,
allowNull: false,
primaryKey: true,
},
}, {
classMethods: {
associate: function(models) {
Product.belongsTo(models.User,{ as : 'ProductManager'});
// associations can be defined here
}
}
});
Product.sync({force: true}).then(() => {
console.log('Sequelize forced');
})
return Product;
};
user.jsの
module.exports = (sequelize, DataTypes) => {
const User = sequelize.define('User', {
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true,
allowNull: false,
},
password: {
type: DataTypes.STRING,
allowNull: false,
},
email: {
type: DataTypes.STRING,
unique: true,
},
}, {
classMethods: {
associate: (models) => {
// associations can be defined here
User.hasMany(models.Product);
},
},
freezeTableName: true,
});
// FORCE FOR NOW Use only if make model changes
User.sync({force: true}).then(() => {
console.log('Sequelize forced');
})
return User;
};
方言:のPostgres Sequelizeバージョン: 3.30.1
Psと。私はもともと、モデルファイルを生成するためにsequelize-cliを使用し、次に私のニーズに変更しました。