Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find module 'sequelize/types'

anyone knows why i am getting this error this is my code

"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");
  },
};

when am trying to run this command sequelize db:migrate and its showing me ERROR: Cannot find module 'sequelize/types'

my dependencies file

  "dependencies": {
"@types/sequelize": "^4.28.9",
    "express": "^4.17.1",
    "mysql2": "^2.2.5",
    "sequelize": "^6.5.0",
    "sequelize-cli": "^6.2.0"  }

any solution need help

like image 676
Aakash Avatar asked Mar 05 '21 05:03

Aakash


2 Answers

"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");
  },
};
like image 61
Yang Yu Avatar answered Oct 28 '22 16:10

Yang Yu


If you change the second line to;

const { DataTypes } = require("sequelize");

It should work fine.

like image 20
Bin Emmanuel Avatar answered Oct 28 '22 16:10

Bin Emmanuel