-
Notifications
You must be signed in to change notification settings - Fork 127
FEAT: Support 5.2- Added composite primary key #462
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
base: dev
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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'.
# Set fallback tupple lookup support | |
# Set fallback tuple lookup support |
Copilot uses AI. Check for mistakes.
For this task there is a dependency on subquery lookup using tuple |
Looks like django/django#19565 was merged. @bewithgaurav thanks so much for stepping in to help this project along! |
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
, modifyDatabaseFeatures
, and update schema creation logic to handle composite primary keys.Support for Composite Primary Keys:
mssql/features.py
: Added conditional import ofCompositePrimaryKey
based on Django version and updatedDatabaseFeatures
to includesupports_composite_primary_keys
. Also setsupports_tuple_lookups
toFalse
as a fallback when composite primary keys are supported. [1] [2]mssql/schema.py
: Added conditional import ofCompositePrimaryKey
and updated thecreate_model
method to detect and handle composite primary keys. This includes generating aPRIMARY KEY
SQL clause for composite keys and inserting it into the constraints list during table creation. [1] [2] [3]