相关疑难解决方法(0)

sequelize:关联引用了错误的外键列名

我在这个问题上挣扎了几个小时,我似乎无法找到解决这个令人困惑的错误的方法。我正在尝试使用连接表进行查询并使用嵌套对象显示结果。

所以表是这样的:blogsaccounts通过表上的外键accounts_idblogs表相关联,这似乎是一个简单的连接查询,但我不能让 sequelize 使用正确的外键列名,因为它认为外键被称为account_id

模型是这样定义的:

帐户:

module.exports = function(sequelize, DataTypes) {
    return sequelize.define('accounts', {
        id: {
            type: DataTypes.INTEGER(11),
            allowNull: false,
            primaryKey: true,
            autoIncrement: true
        },
        username: {
            type: DataTypes.STRING,
            allowNull: false
        },
        ............
    }, {
        tableName: 'accounts',
        timestamps: false,
        freezeTableName: true
    });
Run Code Online (Sandbox Code Playgroud)

博客:

module.exports = function(sequelize, DataTypes){
    var model = sequelize.define("blogs", {
        id: {
            type: DataTypes.INTEGER(11),
            allowNull: false,
            primaryKey: true,
            autoIncrement: true
        },
        title: {
            type: DataTypes.STRING,
            allowNull: false,
        },
        content: …
Run Code Online (Sandbox Code Playgroud)

sequelize.js

2
推荐指数
1
解决办法
2871
查看次数

标签 统计

sequelize.js ×1