Reputation: 4427
I wanted to update column to set not null to false, however running db:migration fails with this error message:
Cannot read property 'key' of undefined
Here's the code of migration:
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.changeColumn('Notes', 'title', {
allowNull: false
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.changeColumn('Notes', 'title', {
allowNull: true
});
}
};
As followed document, it seems nothing wrong with my code.
Table and field are exists, what am I wrong?
Upvotes: 3
Views: 2809
Reputation: 59
You must have to provide the column type either you want to change it or not.
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.changeColumn('Notes', 'title', {
type: Sequelize.STRING,
allowNull: false
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.changeColumn('Notes', 'title', {
type: Sequelize.STRING,
allowNull: true
});
}
};
Upvotes: 0
Reputation: 133
Just had this problem myself. From what I see in the source code Sequelize assumes you always provide the type when changing the column. I see it's also in the documentation you linked: "Please make sure, that you are completely describing the new data type."
Upvotes: 2
Reputation: 61
Just a tip how you can fix it. I think query interface object is not able to find the name or column of the table which has to be migrated. Can you just print your Sequelize object and models inside it and put the same name which your Sequelize object holds. I have tried the same library and it works like a charm.
Upvotes: 1