mangulom
mangulom

Reputation: 103

there isn´t method success in sequelize.sync

I´ve the following code, imports the model enter image description here

I get the error in line 11. Doesn´t exist method success

enter image description here

Upvotes: 3

Views: 4056

Answers (2)

Jordy Cuan
Jordy Cuan

Reputation: 487

in addition to @robertklep answer, success() is deprecated so you need then() function instead.

The result would be:

sequelize.sync().then(function() {
    Quiz.count().then(function (count){
        if(count === 0) {
            Quiz.create({ 
                pregunta: 'Capital de Italia',
                respuesta: 'Roma'
            })
            .then(function(){console.log('log')});
        }
    });
});

The same in quiz_controller.js

Upvotes: 2

robertklep
robertklep

Reputation: 203329

Sequelize uses the bluebird package for its Promise implementation, and as you can see here, its API doesn't support .success() (which also isn't a valid Promises/A+ method).

Instead, use .then():

sequelize.sync().then(function() {
  ...called if successful...
}, function(err) {
  ...called if an error occurred...
});

Upvotes: 9

Related Questions