Skip to content

FEAT: Support 5.2- Added composite primary key #462

New issue

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

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

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

NandanaRaol
Copy link
Contributor

This pull request introduces support for composite primary keys in Django 5.2 and later for the MSSQL backend. It includes changes to conditionally import CompositePrimaryKey, modify DatabaseFeatures, and update schema creation logic to handle composite primary keys.

Support for Composite Primary Keys:

  • mssql/features.py: Added conditional import of CompositePrimaryKey based on Django version and updated DatabaseFeatures to include supports_composite_primary_keys. Also set supports_tuple_lookups to False as a fallback when composite primary keys are supported. [1] [2]

  • mssql/schema.py: Added conditional import of CompositePrimaryKey and updated the create_model method to detect and handle composite primary keys. This includes generating a PRIMARY KEY SQL clause for composite keys and inserting it into the constraints list during table creation. [1] [2] [3]

@Copilot Copilot AI review requested due to automatic review settings June 17, 2025 04:15
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for composite primary keys for the MSSQL backend in Django 5.2 and later. It conditionally imports CompositePrimaryKey, updates database features to reflect composite primary key support, and revises schema creation logic to generate a proper PRIMARY KEY clause for composite keys.

  • Introduces conditional imports for CompositePrimaryKey based on the Django version.
  • Updates DatabaseFeatures to include composite primary key support and disable tuple lookups when applicable.
  • Enhances schema creation logic to handle composite primary keys by generating and inserting a PRIMARY KEY SQL clause.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
mssql/schema.py Added logic to generate a composite primary key SQL clause during table creation.
mssql/features.py Conditionally sets support flags for composite primary keys and tuple lookups.

# CompositePrimaryKey support is only available in Django 5.2 and later
supports_composite_primary_keys = django_version >= (5, 2)
if django_version >= (5, 2) and isinstance(CompositePrimaryKey, type):
# Set fallback tupple lookup support
Copy link
Preview

Copilot AI Jun 17, 2025

Choose a reason for hiding this comment

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

Misspelling: 'tupple' should be corrected to 'tuple'.

Suggested change
# Set fallback tupple lookup support
# Set fallback tuple lookup support

Copilot uses AI. Check for mistakes.

@NandanaRaol NandanaRaol changed the title FEAT: Added composite primary key support FEAT: Support 5.2- Added composite primary key support Jun 17, 2025
@NandanaRaol NandanaRaol changed the title FEAT: Support 5.2- Added composite primary key support FEAT: Support 5.2- Added composite primary key Jun 17, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant