【问题标题】:Could not find migration method: up找不到迁移方法:向上
【发布时间】:2019-12-19 09:43:11
【问题描述】:

我无法将我的模型迁移到 MySQL 数据库。它向我抛出了以下错误:

已加载配置文件“config\config.json”。 使用环境“开发”。 (节点:5828)[SEQUELIZE0004] DeprecationWarning:布尔值已传递给 options.operatorsAliases。这是 v5 的无操作,应该被删除。 == 20191218125700-mig_admin_roles:迁移=======

错误:找不到迁移方法:向上

models- admin_user.js


module.exports = (sequelize, DataTypes) => {
  {
    var admin_users = sequelize.define("adminUser", {
      id: {
        type: DataTypes.INTEGER(22),
        allowNull: false,
        primaryKey: true,
        autoIncrement: true,
        field: "id"
      },
      fname: {
        type: DataTypes.STRING(20),
        allowNull: false,
        field: "fname"
      },
      lname: {
        type: DataTypes.STRING(20),
        allowNull: true,
        field: "lname"
      },
      phoneNo: {
        type: DataTypes.STRING(20),
        allowNull: false,
        field: "phoneNo"
      },
      emailId: {
        type: DataTypes.STRING(20),
        allowNull: false,
        unique: true,
        field: "emailId"
      },
      isActive: {
        type: DataTypes.BOOLEAN,
        allowNull: false,
        defaultValue: "0",
        field: "isActive"
      },
      password: {
        type: DataTypes.STRING(128),
        allownull: false,
        field: "password"
      }
    });
    admin_users.associate = models => {
      admin_users.hasMany(models.adminRole, {
        foreignKey: "roleId"
      });
    };

    return admin_users;
  }
};

迁移:mig-admin_user.js

"use strict";

module.exports = {
  up: (queryInterface, Sequelize) => {
    return queryInterface.createTable("adminUser", {
      id: {
        type: Sequelize.INTEGER(22),
        allowNull: false,
        primaryKey: true,
        autoIncrement: true,
        field: "id"
      },
      fname: {
        type: Sequelize.STRING(20),
        allowNull: false,
        field: "fname"
      },
      lname: {
        type: Sequelize.STRING(20),
        allowNull: true,
        field: "lname"
      },
      phoneNo: {
        type: Sequelize.STRING(20),
        allowNull: false,
        field: "phoneNo"
      },
      emailId: {
        type: Sequelize.STRING(20),
        allowNull: false,
        unique: true,
        field: "emailId"
      },
      isActive: {
        type: Sequelize.BOOLEAN,
        allowNull: false,
        defaultValue: "0",
        field: "isActive"
      },
      password: {
        type: Sequelize.STRING(128),
        allownull: false,
        field: "password"
      }
    });
  },

  down: (queryInterface, Sequelize) => {
    /*
      Add reverting commands here.
      Return a promise to correctly handle asynchronicity.

      Example:
      return queryInterface.dropTable('users');
    */
  }
};

我尝试查找此特定错误,但找不到任何内容。 谁能告诉我哪里出错了?

【问题讨论】:

    标签: mysql node.js sequelize.js sequelize-cli


    【解决方案1】:

    您需要在项目的根目录中添加一个.sequelizerc,它包含如下内容:

    module.exports = {
      'config': 'database/config.js',
      'migrations-path': 'database/migrations',
      'seeders-path': 'database/seeders'
    }
    

    而且你必须指出你的迁移位于哪里。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-14
      • 2017-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-26
      相关资源
      最近更新 更多