sequelize table without column #39;id#39;(续集没有列“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
});
这篇关于续集没有列“id"的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:续集没有列“id"的表
基础教程推荐
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
