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

1

5

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.

Grata answered 7/7, 2017 at 12:46 Comment(4)
Are you using sequelize-cli for migrationsDonnettedonni
@Shivam: No , i am not using sequelize-cli. i am using "sequelize": "^3.24.3".Grata
If manually i have created tables, then it is working for insert queries. but i dont want to create tables manually. Force: true should map schema.Grata
i have added models.sequelize.sync({ force: true, logging: console.log })), in console now i can see all the tables are droped and then again created. but still while insertion i am getting error ER_NO_SUCH_TABLE: Table 'DatabaseName.TableName' doesn't exist.Grata
G
7

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.

Grata answered 19/7, 2017 at 13:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.