sequelize.sync({force:true})有时无法正常工作 [英] sequelize.sync({ force: true }) is not working some times

查看:971
本文介绍了sequelize.sync({force:true})有时无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用gulp任务迁移数据库.为了测试目的,我使用了不同的数据库.所以我需要完全相同的数据库.我正在尝试使用sequelize.sync({force:true}),但无法正常工作.

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 }))
....
....
....
)

使用Force:正确,它应该可以工作,但是对我来说,我遇到了类似mydatbaseName.tablename的错误.

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

我已经创建了新的测试数据库.我不想在testdatabase中手动创建所有内容,因此我正在使用迁移,但是我gusse同步无法正常工作.

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?

预先感谢.

推荐答案

最后,我发现了错误. models.sequelize.sync({ force: true }) 它工作正常,但是我在命令提示符下看不到任何日志,所以我认为同步工作不正常.我已经添加了 models.sequelize.sync({ force: true, logging: console.log })) 有了这个,我能够看到日志,它正在删除所有表并再次创建.问题不在于sequelize.sync().我的数据库名称有问题,它仅引用开发数据库,​​而我正在testDatabase上执行查询.

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.

在运行测试之前,我只是更改了数据库,例如 export MYSQL_DATABASENAME = test_database_name. 问题解决了.

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

这篇关于sequelize.sync({force:true})有时无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆