mysql - 找不到模块 'sequelize/types'

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

任何人都知道为什么我会收到此错误
这是我的代码

"use strict";
const { DataTypes } = require("sequelize/types");

module.exports = {
  up: async (queryInterface, DataTypes) => {
    await queryInterface.createTable("dummytables", {
      id: {
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        type: DataTypes.INTEGER,
      },
      id: {
        type: DataTypes.NUMBER,
      },
      first_name: {
        type: DataTypes.STRING,
        allowNull: false,
      },
      last_name: {
        type: DataTypes.STRING,
        allowNull: false,
      },
    });
  },
  down: async (queryInterface, DataTypes) => {
    await queryInterface.dropTable("dummytables");
  },
};
当我试图运行这个命令时 sequelize db:migrate它向我展示了ERROR: Cannot find module 'sequelize/types'我的依赖文件
  "dependencies": {
"@types/sequelize": "^4.28.9",
    "express": "^4.17.1",
    "mysql2": "^2.2.5",
    "sequelize": "^6.5.0",
    "sequelize-cli": "^6.2.0"  }
任何解决方案都需要帮助

最佳答案

"use strict";
//const { DataTypes } = require("sequelize/types"); // Remove this line

module.exports = {
  up: async (queryInterface, DataTypes) => {
    await queryInterface.createTable("dummytables", {
      id: {
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        type: DataTypes.INTEGER,
      },
      id: {
        type: DataTypes.NUMBER,
      },
      first_name: {
        type: DataTypes.STRING,
        allowNull: false,
      },
      last_name: {
        type: DataTypes.STRING,
        allowNull: false,
      },
    });
  },
  down: async (queryInterface, DataTypes) => {
    await queryInterface.dropTable("dummytables");
  },
};

关于mysql - 找不到模块 'sequelize/types',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66487330/

相关文章:

php - MySQL/PHP : Search rows by datetime RANGE given overlaps in the table

MySQL如何将十进制值转换为度、分、秒

PHP mysql 更新查询不起作用

php - mySQL 和 PHP 的最佳性能 : Lots of small queries, 还是一个大的?

javascript - 将socket.io事件分离到不同的文件中

node.js - sequelize 中的异步 getterMethods

javascript - 如何在xml2js xml的CDATA中添加html标签?

node.js - 吉普 错误!堆栈错误: `C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe` failed with exit code: 1

node.js - 我如何使用sequelize-typescript从单个字段引用多个模型?

node.js - 如何在不使用等待的情况下返回对象