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

久未见 提交于 2020-05-15 05:19:06

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/44971151/sequelize-sync-force-true-is-not-working-some-times

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!