Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting ER_ROW_IS_REFERENCED after adding references #2211

Closed
burakkilic opened this issue Aug 29, 2014 · 2 comments
Closed

Getting ER_ROW_IS_REFERENCED after adding references #2211

burakkilic opened this issue Aug 29, 2014 · 2 comments

Comments

@burakkilic
Copy link

Hi;

I am syncing db with my models everytime I start my server.

   sequelize
  .sync({force: true})
  .complete(function(err){
    if(err) console.log("An error occured %j",err);
    else console.log("Database dropped and synchronized");
});

After adding references, I am getting:

An error occured         [[{"code":"ER_ROW_IS_REFERENCED","errno":1217,"sqlState":"23000","index":0,"sql":"DROP TABLE IF EXISTS `users`;"}],[{"code":"ER_ROW_IS_REFERENCED","errno":1217,"sqlState":"23000","index":0,"sql":"DROP TABLE IF EXISTS `languages`;"}]]

because of references, it cannot drop 2 tables.

What can I do to force it?

@mickhansen
Copy link
Contributor

You can execute a query that turns off foreign key constraints, atleast that's what i've seen someone else do to resolve this issue (don't recall the exact issue right now but it was similar).

@burakkilic
Copy link
Author

I found the solution as:

sequelize.query('SET FOREIGN_KEY_CHECKS = 0')
.then(function() {
    return sequelize
        .sync({
            force: true
        });
})
.then(function() {
    return sequelize.query('SET FOREIGN_KEY_CHECKS = 1')
})
.then(function() {
    console.log('Database synchronised.');
}, function(err) {
    console.log(err);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants