续集没有列“id"的表
我有以下表的sequelize定义:
I have the following sequelize definition of a table:
AcademyModule = sequelize.define('academy_module', {
academy_id: DataTypes.INTEGER,
module_id: DataTypes.INTEGER,
module_module_type_id: DataTypes.INTEGER,
sort_number: DataTypes.INTEGER,
requirements_id: DataTypes.INTEGER
}, {
freezeTableName: true
});
如您所见,此表中没有 id
列.但是,当我尝试插入时,它仍然会尝试以下 sql:
As you can see there is not an id
column in this table. However when I try to insert it still tries the following sql:
INSERT INTO `academy_module` (`id`,`academy_id`,`module_id`,`sort_number`) VALUES (DEFAULT,'3',5,1);
如何禁用它明显具有的 id
功能?
How can I disable the id
function it clearly has?
推荐答案
如果你没有定义 primaryKey
那么 sequelize 默认使用 id
.
If you don't define a primaryKey
then sequelize uses id
by default.
如果您想自己设置,只需在您的列上使用 primaryKey: true
.
If you want to set your own, just use primaryKey: true
on your column.
AcademyModule = sequelize.define('academy_module', {
academy_id: {
type: DataTypes.INTEGER,
primaryKey: true
},
module_id: DataTypes.INTEGER,
module_module_type_id: DataTypes.INTEGER,
sort_number: DataTypes.INTEGER,
requirements_id: DataTypes.INTEGER
}, {
freezeTableName: true
});
相关文章