sequelize 迁移未运行 [英] sequelize migrations not running

查看:18
本文介绍了sequelize 迁移未运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 Sequelize 时遇到了一个我以前从未遇到过的奇怪问题,当我尝试运行迁移时没有任何反应.我得到以下输出:

I'm having a weird issue with Sequelize I haven't encountered before, when I try to run my migrations nothing happens. I get the following output:

Loaded configuration file "configconfig.json"
Using environment "development"

而且程序刚刚存在.

我已经多次检查我的代码,一切都检查出来了.

I've checked my code multiple times over and everything checks out.

型号代码:

module.exports = {
up: (queryInterface, Sequelize) => {
    return queryInterface.createTable("users", {
        id: {
            allowNull: false,
            autoIncrement: true,
            primaryKey: true,
            type: Sequelize.INTEGER
        },
        username: {
            type: Sequelize.STRING,
            unique: true,
            allowNull: false,
            validate: {
                notEmpty: true
            }
        },
        email: {
            type: Sequelize.STRING,
            unique: true,
            allowNull: false,
            validate: {
                notEmpty: true,
                isEmail: true
            }
        },
        password: {
            type: Sequelize.STRING,
            allowNull: false,
            validate: {
                notEmpty: true,
                len: [7, 42]
            }
        },
        createdAt: {
            type: Sequelize.DATE
        },
        updatedAt: {
            type: Sequelize.DATE
        }
    })
},
down: (queryInterface, Sequelize) => {
    return queryInterface.dropTable("users")
}

}

这是我的模型/index.js 中的一个片段:

And here is a snippet from my model/index.js:

const fs = require("fs")
const path = require("path")
const Sequelize = require("sequelize")

const basename = path.basename(__filename)
const env = process.env.TEST_ENV || "development"
const config = require(`${__dirname}/../config/config.js`)[env]
const db = {}

console.log('config', config)

let sequelize
if (config.use_env_variable) {
    sequelize = new Sequelize(process.env[config.use_env_variable], config)
} else {
    sequelize = new Sequelize(
        config.database,
        config.username,
        config.password,
        config
    )
}

这几乎就像 sequelize 没有获取任何迁移文件一样.我不确定我应该如何解决这个问题.对此的任何帮助将不胜感激.

It's almost like sequelize just isn't picking up any of migrations file. I'm not sure how I should troubleshoot this. Any help on this would be much appreciated.

推荐答案

所以问题出在节点版本上.

So the issue was with node versions.

我可能应该提供更多的上下文开始,但我换了笔记本电脑,在新笔记本电脑上安装了 14.1.0 版,而在旧笔记本电脑上安装了 10.13.0 版!.所以切换版本成功了.

I probably should have provided more context to start of with but I switched laptops and on new laptop I had version 14.1.0 installed whereas on old laptop I had version 10.13.0 installed!. So switching versions did the trick.

这篇关于sequelize 迁移未运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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