SQL Server Error 1785: Migration V2.9.0.20210423125133__assets_tags.sql fails with cascade delete conflict
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 151
- Forks
- 183
- Avg merge
- 14m
- Merged PRs (30d)
- 2
Description
Description
The Flyway migration V2.9.0.20210423125133__assets_tags.sql fails on SQL Server with Error 1785 due to multiple cascade delete paths on the tag_groups table.
Environment
- WebAPI Version: 2.8.1
- Database: Microsoft SQL Server 12.0 (Azure SQL Database)
- Database Driver: com.microsoft.sqlserver.jdbc.SQLServerDriver (mssql-jdbc-10.2.1)
- Flyway Version: 4.2.0
Error Message
SQL State : S0000
Error Code : 1785
Message : Introducing FOREIGN KEY constraint 'tag_groups_tag_fk' on table 'tag_groups' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Location : db/migration/sqlserver/V2.9.0.20210423125133__assets_tags.sql
Root Cause
The migration creates the tag_groups table with two foreign keys, both with ON DELETE CASCADE, both referencing the same parent table (tags):
CREATE TABLE webapi.tag_groups
(
tag_id INT NOT NULL,
group_id INT NOT NULL,
CONSTRAINT tag_groups_group_fk FOREIGN KEY (group_id) REFERENCES webapi.tags (id) ON DELETE CASCADE,
CONSTRAINT tag_groups_tag_fk FOREIGN KEY (tag_id) REFERENCES webapi.tags (id) ON DELETE CASCADE
);
Steps to Reproduce
- Set up fresh SQL Server database
- Configure WebAPI 2.8.1 to connect to SQL Server
- Enable Flyway migrations
- Start application
- Migration fails with Error 1785
Logs
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with db/migration/sqlserver/V2.9.0.20210423125133__assets_tags.sql and inspect the two foreign keys on webapi.tag_groups. Run the Flyway migration against a fresh SQL Server database to reproduce Error 1785, then verify the migration completes successfully without introducing an invalid cascade path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- sql
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100