问题描述
"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,});
},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,});
},down: async (queryInterface,DataTypes) => {
await queryInterface.dropTable("dummytables");
},};
,
如果你把第二行改为;
const { DataTypes } = require("sequelize");
它应该可以正常工作。