Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does sequelize.sync() work, specifically the force option?

Tags:

sequelize.js

What does the force option on sequelize.sync() do?

sequelize.sync({     force: true }); 

Specifically, I am interested in knowing what force: false does? Will it not sync the schema with the database?

Are there any formal docs for sequelize? I could only find examples inside the docs.

like image 704
Naresh Avatar asked Jan 11 '14 19:01

Naresh


People also ask

What does Sequelize sync () do?

The Sequelize instance method sync() is used to synchronize your Sequelize model with your database tables. The synchronization happens at the table level. When your table doesn't exist the sync() method will generate and run a CREATE TABLE statement for you.

What is Sequelize Sync force true?

To your question: force: true adds a DROP TABLE IF EXISTS before trying to create the table - if you force, existing tables will be overwritten. Follow this answer to receive notifications.

Where do I call Sequelize sync?

Typically your . sync() call will be in your server file and the var User = sequelize. define("ModelName"... will be in your models/modelName. js file.


1 Answers

(More or less) formal docs and API reference can be found at http://sequelize.readthedocs.org/en/latest/api/sequelize/#sync

To your question: force: true adds a DROP TABLE IF EXISTS before trying to create the table - if you force, existing tables will be overwritten.

like image 135
Jan Aagaard Meier Avatar answered Sep 21 '22 02:09

Jan Aagaard Meier