Synchronizing the model with the database

If you want Sequelize to automatically create the table (or modify it as needed) according to your model definition, you can use the sync method, as follows:

  1. // Note: using `force: true` will drop the table if it already exists
  2. User.sync({ force: true }).then(() => {
  3. // Now the `users` table in the database corresponds to the model definition
  4. return User.create({
  5. firstName: 'John',
  6. lastName: 'Hancock'
  7. });
  8. });

Synchronizing all models at once

Instead of calling sync() for every model, you can call sequelize.sync() which will automatically sync all models.

Note for production

In production, you might want to consider using Migrations instead of calling sync() in your code. Learn more in the Migrations guide.