Skip to content

Delimit named default constraints in SqlServerMigrationsSqlGenerator - #39384

Merged
AndriySvyryd merged 1 commit into
dotnet:mainfrom
ilkertskn:fix/sqlserver-default-constraint-name-delimit
Oct 22, 2026
Merged

AndriySvyryd merged 1 commit into
dotnet:mainfrom
ilkertskn:fix/sqlserver-default-constraint-name-delimit

Conversation

@ilkertskn

Copy link
Copy Markdown
Contributor

DefaultConstraintName was wrapped in brackets by hand, so a ']' in the name wasn't escaped and produced invalid SQL when adding or dropping the constraint.

  • [x ] I've read the guidelines for contributing and seen the walkthrough
  • [ x] I've posted a comment on an issue with a detailed description of how I am planning to contribute and got approval from a member of the team
  • [ x] The code builds and tests pass locally (also verified by our automated build checks)
  • [ x] Commit messages follow this format:
        Summary of the changes
        - Detail 1
        - Detail 2

        Fixes #bugnumber
  • [x ] Tests for the changes have been added (for bug fixes / features)
  • [ x] Code follows the same patterns and style as existing code in this repo

DefaultConstraintName was wrapped in brackets by hand, so a ']' in the
name wasn't escaped and produced invalid SQL when adding or dropping the
constraint.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The reviewed changes address the escaping bug and include regression coverage for both affected SQL generation paths.

No open issues 🎉

What changed in this PR

This pull request fixes SQL Server migration generation for named default constraints containing ] by using the provider’s identifier-delimiting helper to escape constraint names correctly.

Changes:

  • Delimits named default constraints when adding columns.
  • Delimits named default constraints when dropping constraints.
  • Adds regression tests for constraint names containing ].
File Description
test/​EFCore.SqlServer.FunctionalTests/​Migrations/​SqlServerMigrationsSqlGeneratorTest.cs Verifies correct escaping in generated add and drop constraint SQL.
src/​EFCore.SqlServer/​Migrations/​SqlServerMigrationsSqlGenerator.cs Uses DelimitIdentifier for named default constraints during creation and removal.

Review effort: Lite

@AndriySvyryd AndriySvyryd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution!

@AndriySvyryd
AndriySvyryd merged commit 8998c74 into dotnet:main Oct 22, 2026
19 of 20 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants