2

I'm running sequelize-cli db:migrate to initialize a migration, but this happens

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')

This is my config.js file:

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

This is my migration file:

'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');
  }
};

This is my package.json file:

{
  "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"
  }
}

I already tried out some resolutions from other posts, but it didn't work out. Can someone help me with this? (Some words in these codes are in portuguese, don't worry about it)

Khiuta
  • 21
  • 2
  • You don't appear to have any code trying to access `.type`. Have you searched the Sequelize issues list or considered raising a new one? – Phil Feb 21 '23 at 23:48

2 Answers2

0

Try dividing your configuration by environment how the Migrations configuration documentation shows:

config/config.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"
  }
}

You also can just return queryInterface instead of await queryInterface.

Wesley LeMahieu
  • 2,296
  • 1
  • 12
  • 8
0

I think you have a typo on your date columns.

      createdAt: {
        type: Sequelize.DATA,
      },

      updatedAt: {
        type: Sequelize.DATA,
      },

I think you meant Sequelize.DATE. That might be what's causing the error. Boa sorte!