Reputation: 793
I have added migration for add new column like this:
module.exports = {
up: function(migration, DataTypes, done) {
migration.addColumn('Topics','isFeatured',{
type: DataTypes.BOOLEAN, defaultValue: false
})
done()
},
down: function(migration, DataTypes, done) {
migration.removeColumn('Topics', 'isFeatured')
done()
}
}
then run migration as
sequelize -m
its add new column with default value. But when I retrieve this api
updateTopic = function (req, res) {
db.Topic.find(req.params.id).success(function (topic) {
console.log(topic.isFeatured)
// some code
});
};
then I got console.log(topic.isFeatured)
is undefined
but console.log(topic)
show topic with default false value of isFeatured.
So anybody can help me to find out why console.log(topic.isFeatured)
is undefined.
Thanks
Upvotes: 1
Views: 892
Reputation: 9095
It seems that you have not added isFeatured
column in your model definitions, you have to add it to your model definitions.
module.exports = function (db, DataTypes) {
var Topic = sequelize.define('Topic', {
name: DataTypes.STRING,
// other columns
isFeatured: DataTypes.BOOLEAN
});
return Topic;
}
Upvotes: 3