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

Sequelize forgets cascade rules in belongsToMany if timestamps is true #14030

Open
2 of 7 tasks
LubosD opened this issue Jan 30, 2022 · 0 comments
Open
2 of 7 tasks

Sequelize forgets cascade rules in belongsToMany if timestamps is true #14030

LubosD opened this issue Jan 30, 2022 · 0 comments

Comments

@LubosD
Copy link

LubosD commented Jan 30, 2022

Issue Creation Checklist

[x] I have read the contribution guidelines

Bug Description

SSCCE

Here is the link to the SSCCE for this issue: https://github.com/LubosD/sequelize-sscce/blob/master/src/sscce.js

What do you expect to happen?

I want Sequelize to correctly set ON DELETE CASCADE rules on ArticlePrice table so that I can delete PriceList items without triggering a constraint failure.

What is actually happening?

Sequelize DROPs and CREATEs the tables multple times during synchronization, but strangely forgets ON DELETE CASCADE when creating the table the last time, which makes SQLite throw a constraint failure when truncating the PriceList table.

  original: [Error: SQLITE_CONSTRAINT: FOREIGN KEY constraint failed] {
    errno: 19,
    code: 'SQLITE_CONSTRAINT',
    sql: 'DELETE FROM `PriceLists`'
  },
  sql: 'DELETE FROM `PriceLists`',

Additional context

This only happens if alter: true is set when calling sequelize.sync() AND timestamps: true is set on the sequelize instance. Set either of them to false and the bug doesn't appear.

The bug reappears if I add any additional columns to ArticlePrice, which probably explains that timestamps affects it as well.

Environment

  • Sequelize version: 6.15.0
  • Node.js version: v16.13.2

Bug Report Checklist

How does this problem relate to dialects?

  • I think this problem happens regardless of the dialect.
  • I think this problem happens only for the following dialect(s):
  • I don't know, I was using SQLite, with connector library version 4.2.0 and database version 4.2.0

Would you be willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time and I know how to start.
  • Yes, I have the time but I don't know how to start, I would need guidance.
  • No, I don't have the time, although I believe I could do it if I had the time...
  • No, I don't have the time and I wouldn't even know how to start.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants