mysql Sequelize CLI迁移错误无法读取未定义的属性(阅读“type”)

nr7wwzry  于 2023-02-28  发布在  Mysql
关注(0)|答案(1)|浏览(142)

我正在运行sequelize-cli db:migrate来初始化迁移,但发生了这种情况

Sequelize CLI \[Node: 19.6.1, CLI: 6.6.0, ORM: 6.28.1\]

Loaded configuration file "config\\config.js".
== 20230221223939-aluno: migrating =======

ERROR: Cannot read properties of undefined (reading 'type')

这是我的config.js文件:

module.exports = {
    dialect: 'postgres',
    host: 'localhost',
    username: 'postgres',
    password: '123456',
    database: 'projetoBiblioteca',
    define: {
        timestamps: true,
    },
};

这是我的迁移文件:

'use strict';

module.exports = {
  up: async (queryInterface, Sequelize) => {
    await queryInterface.createTable('aluno', {
      matricula: {
        type: Sequelize.INTEGER,
        allowNull: false,
        primaryKey: true,
        autoIncrement: false,
      },

      nome: {
        type: Sequelize.STRING,
        allowNull: false,
      },

      curso: {
        type: Sequelize.STRING,
        allowNull: false,
      },

      ano: {
        type: Sequelize.INTEGER,
        allowNull: false,
      },

      createdAt: {
        type: Sequelize.DATA,
      },

      updatedAt: {
        type: Sequelize.DATA,
      },
    });
  },

  down: async (queryInterface, Sequelize) => {
    await queryInterface.dropTable('aluno');
  }
};

这是我的package.json文件:

{
  "name": "projetobiblioteca",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.18.2",
    "pg": "^8.9.0",
    "pg-hstore": "^2.3.4",
    "sequelize": "^6.28.1"
  },
  "devDependencies": {
    "nodemon": "^2.0.20"
  }
}

我已经尝试了一些决议从其他职位,但它没有工作。有人能帮我这个吗?(有些话在这些代码是葡萄牙语,不要担心)

ovfsdjhp

ovfsdjhp1#

尝试按迁移配置文档所示的环境划分配置:

配置/配置json

{
  "development": {
    "username": "root",
    "password": null,
    "database": "database_development",
    "host": "127.0.0.1",
    "dialect": "mysql"
  },
  "test": {
    "username": "root",
    "password": null,
    "database": "database_test",
    "host": "127.0.0.1",
    "dialect": "mysql"
  },
  "production": {
    "username": "root",
    "password": null,
    "database": "database_production",
    "host": "127.0.0.1",
    "dialect": "mysql"
  }
}

您也可以只使用return queryInterface而不是await queryInterface

相关问题