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
Try dividing your configuration by environment how the Migrations configuration documentation shows:
config/config.json
You also can just
return queryInterface
instead ofawait queryInterface
.I think you have a typo on your date columns.
I think you meant
Sequelize.DATE
. That might be what’s causing the error. Boa sorte!