简体   繁体   English

找不到sequelize列中的错误

[英]Error in sequelize column is not found

I have created the following model in sequelize: 我在续集中创建了以下模型:

export function initialize(sequelize: Sequelize.Sequelize, dataTypes: Sequelize.DataTypes): SalesPerson.Model {
    var salesPersonModel = sequelize.define<SalesPerson, SalesPerson.Pojo>('salesPerson', {
        ownerId: { type: dataTypes.STRING, allowNull: false, field: 'owner_id' },
        firstName: { type: dataTypes.STRING, allowNull: false, field: 'first_name' },
        lastName: { type: dataTypes.STRING, allowNull: false, field: 'last_name' },
        email: { type: dataTypes.STRING, allowNull: false }
    }, {
        underscored: true,
        tableName: 'sales_persons'
    });

    salesPersonModel.removeAttribute('id');

    return salesPersonModel;
}

after starting sequelize.sync() the table is correctly created. 启动sequelize.sync() ,表已正确创建。 the problem is that when I make a query like this: 问题是当我进行如下查询时:

db.SalesPerson.find({ limit: 1, order: [['updated_at DESC']] })...

I got the following error: 我收到以下错误:

Unhandled rejection SequelizeDatabaseError: ER_BAD_FIELD_ERROR: Unknown column 'salesPerson.updated_at DESC' in 'order clause'

and this has not sense because I see in the database the column so should be something related with sequelize 这没有意义,因为我在数据库中看到该列,因此应该与sequ​​elize有关

That's not how the syntax works. 语法不是这样工作的。 You need to separate the column name from the direction: 您需要将列名与方向分开:

db.SalesPerson.find({ limit: 1, order: [['updated_at', 'DESC']] })...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM