문제

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

도움이 되었습니까?

해결책

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;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top