对没有列'id'的表进行排序 [英] sequelize table without column 'id'

查看:78
本文介绍了对没有列'id'的表进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对表有以下序列定义:

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,则默认情况下续集使用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'的表进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆