0

I created a model using sequelize (the code is below) but dont understand how I can update the model. When I changed the model, the old one (with name,num_stars and amenities) still appears in my db and I thought as long i use - sync() - I do update model changes, but apparently not. Can anyone help? Thank you!

my postgreSQL model: db/index.js:

var db = new Sequelize('postgres://localhost:5432/ajax', {
 logging: false
});

var Hotel = db.define('hotel', {

    name: Sequelize.STRING,
    num_stars: {
     type: Sequelize.INTEGER,
     validate: { min: 1, max: 5 }
   },
    amenities: Sequelize.STRING
})

module.exports=Hotel;

part of server.js

app.listen(1337, function () {
    db.sync()
    .then(function(){
        console.log('Server listening!');
    });
});
web2016
  • 47
  • 9
  • I'm not about to answer because migrations are very application specific, but this is the entire reason for Sequelize's Migrations (http://docs.sequelizejs.com/en/latest/docs/migrations/). You write code defining how the new scheme relates to the old one, and Sequelize runs all your data through it ensuring it's processed according to your rules. – gelliott181 Dec 13 '16 at 18:39

2 Answers2

0

In Sequelize.js, updating a model falls under the migration progress and the only way I know how to do it is via the Sequelize CLI (npm install -g seqelize-cli). This previous post should give you all the answers you need!

Community
  • 1
  • 1
0

Just figured out that all I had to do was to add - sync: true -

var db = new Sequelize('postgres://localhost:5432/ajax', {
logging: false,
sync: true 
});
web2016
  • 47
  • 9