skip to Main Content

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)

2

Answers


  1. 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.

    Login or Signup to reply.
  2. 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!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search