I made a table using sequelize-cli, however I forgot to add a column: title.
So I generated new migration:
$ sequelize migration:create --name update-notes
And put these codes inside of migration file:
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.addColumn(
'Notes',
'title',
Sequelize.STRING
);
},
down: (queryInterface, Sequelize) => {
return queryInterface.removeColumn(
'Notes',
'title'
);
}
};
After run migration and check the table schema from DB, it works:
$ sequelize db:migrate
However model doesn't have my new added column yet:
'use strict';
// models/notes.js
module.exports = (sequelize, DataTypes) => {
const Notes = sequelize.define('Notes', {
content: DataTypes.TEXT // NO 'TITLE' COLUMN
}, {});
Notes.associate = function(models) {
// associations can be defined here
};
return Notes;
};
What am I missing? How should I apply my updates to model file?
Also what if previous data in table is not patible with new table schema? Is it just fail the migration and developer fix the issue manually?
I made a table using sequelize-cli, however I forgot to add a column: title.
So I generated new migration:
$ sequelize migration:create --name update-notes
And put these codes inside of migration file:
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.addColumn(
'Notes',
'title',
Sequelize.STRING
);
},
down: (queryInterface, Sequelize) => {
return queryInterface.removeColumn(
'Notes',
'title'
);
}
};
After run migration and check the table schema from DB, it works:
$ sequelize db:migrate
However model doesn't have my new added column yet:
'use strict';
// models/notes.js
module.exports = (sequelize, DataTypes) => {
const Notes = sequelize.define('Notes', {
content: DataTypes.TEXT // NO 'TITLE' COLUMN
}, {});
Notes.associate = function(models) {
// associations can be defined here
};
return Notes;
};
What am I missing? How should I apply my updates to model file?
Also what if previous data in table is not patible with new table schema? Is it just fail the migration and developer fix the issue manually?