Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i disable Sequelize syncing?

I am trying to connect mysql to my nodejs project. While creating connection to nodejs it automatically creates tables based on models i have defined. I don't want to auto create tables. How do i disable it?

My DB Configuration

var sequelize = new Sequelize(config.db.database, config.db.username, 
config.db.password, {
    host : config.db.host,
    port : config.db.port,
    dialect : config.db.connection
});

My Connection to DB

/* Database Connection */
db.sequelize.sync().then(function() {
  console.log('Nice! Database looks fine')
}).catch(function(err) {
  console.log(err, "Something went wrong with the Database Update!")
});
like image 268
architjn Avatar asked May 01 '26 16:05

architjn


2 Answers

This is how you should confirm the connection ,

db.sequelize
.authenticate()
.then(() => {
    console.log('Connection has been established successfully.');
})
.catch(err => {
    console.error('Unable to connect to the database:', err);
});

sync() is generally for when you want to sync your modals with database , and you still want to use sync , then use it with these options

db.sequelize.sync({
    force : false , // To create table if exists , so make it false
    alter : true // To update the table if exists , so make it true
})
like image 146
Vivek Doshi Avatar answered May 03 '26 05:05

Vivek Doshi


Unless I'm missing something... Just don't call db.sequelize.sync()?

like image 36
AKX Avatar answered May 03 '26 07:05

AKX