How to insert initial data using sequelize migrations/seeds? How to insert initial data using sequelize migrations/seeds? express express

How to insert initial data using sequelize migrations/seeds?


You can use next:

const City = sequelize.define('city', {  name: { type: Sequelize.STRING },  order_: { type: Sequelize.INTEGER }});City.sync().then(() => {  City.create({    name: 'Neuquen',    order_: 0  });  City.create({    name: 'General Roca',    order_: 1  });});

Or read about "migrations" at http://docs.sequelizejs.com/en/latest/docs/migrations/


new Date()

also required for mysql, i.e.

  return queryInterface.bulkInsert('users', [  {    "Forename":"A",    "Surname": "User",    "UserType":"1",    "Email":"auser@gmail.com",    "Password":"password",    "LastLogin":0,    "Tokens": JSON.stringify({"tokens":[]}),    "CreatedBy": 999,    "CreatedAt": new Date(),    "UpdatedAt": new Date()  }]);


An alternative could be use : sequelize fixtures , you could init your tables with default data declared as a json file or other format.