Sequelize.sync({force:true})保持过时的模型架构

时间:2019-04-17 23:50:21

标签: node.js postgresql sequelize.js

我的nodejs / sequelizejs(5.7.6)/ postgres(11.2)应用程序具有一个套接字列表模型,该模型最近进行了如下更新:

const SocketList = db.define('socketlist', {
    user_ids: {type: Sql.ARRAY(Sql.INTEGER),
    },
    fort_token: { 
      type: Sql.STRING      
    },
    server_id: {type: Sql.STRING
    },
}, {
    timestamps: false,
    indexes: [
          {
            fields: ['fort_token']
          },
          {
            fields: ['server_id']
          },
        ]   
});

我正在使用sync创建数据库表:

db.sync({force:true})
    .then((res) => {
        console.log("db done!");
        console.log(res);  
    }); //create db 

问题在于创建的socketlist表仍然基于已经更新的旧模式,我不知道sync在哪里缓存了过时的模式代码。我试图删除整个数据库或表,但结果始终相同-旧的和过时的架构。到目前为止,sync一直运行良好。是sequelizejs的错误吗?代码有什么问题?

findOne()也使用过时的架构,如控制台输出所示:

Socketio server is initialized
Executing (default): SELECT "id", "user_id", "socket_id", "event_id", "server_id", "active" FROM "socketlists" AS "socketlist" WHERE "socketlist"."fort_token" = '12345678901234567890' LIMIT 1;

我卸下并重新安装了sequelize,问题仍然存在。

这是数据库连接:

const Sql = require("sequelize");
const db = new Sql('myDB', 'postgres', `${process.env.DB_PASSWORD}`, {
    host: 'localhost',
    dialect: 'postgres',
    port:5433,
} );

这是旧的(过时的)SocketList模式:

const Sql = require("sequelize");
//const Op = Sql.Op;
const db = require("../startup/db");
const Joi = require('joi');

const SocketList = db.define('socketlist', {
    id: {type: Sql.INTEGER,
         primaryKey:true,
         autoIncrement: true,
         min: 1
    },
    socket_id: {type: Sql.STRING,
                min: 1
    },
    event_id: {type: Sql.INTEGER,
               min: 1
    },
    server_id: {type: Sql.STRING
    },
    active: {type: Sql.BOOLEAN,
             defaultValue: true,
    },
}, {
    timestamps: false
 }, { 
        indexes: [
          {
            //socket_id
            fields: ['socket_id']
          },
          {
            fields: ['active']
          },
          {
            fields: ['server_id']
          },
          {
            fields: ['event_id']
          },
        ]   
}); 

module.exports.SocketList = SocketList; 

0 个答案:

没有答案