Reputation: 1482
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!")
});
Upvotes: 3
Views: 5175
Reputation: 58593
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
})
Upvotes: 8
Reputation: 169388
Unless I'm missing something... Just don't call db.sequelize.sync()
?
Upvotes: 3