Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sequelize.sync({ force: true }) is not working some times

i am using gulp tasks for migration of database. For testing purpose i am using different database. so i need exactly same database. i am trying to do with sequelize.sync({ force: true }) but its not working.

i am having my all models in portal-model. here is the code:

const models = require('portal-models');
gulp.task('migrate', ['create-database'], (done) => {
  models.sequelize.query('SET FOREIGN_KEY_CHECKS = 0')
  .then(() => models.sequelize.sync({ force: true, alter: true }))
....
....
....
)

With Force: true it should work but for me i am getting error like mydatbaseName.tablename is not exists.

i have created new test database. i dont want to manually create everything in testdatabase, so i am using migrations but i gusse sync is not working properly.

Can anyone tell, exactly what should i follow?

Thanks in Advance.

like image 706
Nikita S Avatar asked Jul 07 '17 12:07

Nikita S


1 Answers

Finally i found the mistake. models.sequelize.sync({ force: true }) it was working properly but i was not able to see any logs on command prompt so i thought sync is not working properly. I have added models.sequelize.sync({ force: true, logging: console.log })) With this i was able to see the log, it was dropping all tables and again creating. The problem was not with sequelize.sync() . Problem was with my database name, it was referring development database only, and i was executing queries on testDatabase.

before running test, i just changed my database like export MYSQL_DATABASENAME = test_database_name . And issue solved.

like image 163
Nikita S Avatar answered Oct 14 '22 12:10

Nikita S