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!")
});
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
})
Unless I'm missing something... Just don't call db.sequelize.sync()?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With