summaryrefslogtreecommitdiff
path: root/django/db/migrations
AgeCommit message (Collapse)Author
2026-04-20Refs #36005 -- Made OperationCategory subclass StrEnum.Clifford Gama
2026-02-02Fixed #36893 -- Serialized elidable kwarg for RunSQL and RunPython operations.SnippyCodes
2026-01-28Fixed #36878 -- Unified data type for *_together options in ModelState.Markus Holtermann
Ever since the beginning of Django's migration framework, there's been a bit of an inconsistency on how index_together and unique_together values have been stored on the ModelState[^1]. It's only really obvious, when looking at the current code for `from_model()`[^2] and the `rename_field()` state alteration code[^3]. The problem in the autodetector's detection of the `*_together` options as raised in the ticket, reinforces the inconsistency[^4]: the old value is being normalized to a set of tuples, whereas the new value is taken as-is. Why this hasn't been caught before, is likely to the fact, that we never really look at a `to_state` that comes from migration operations in the autodetector. Instead, in both usages in Django[^5], [^6] the `to_state` is a `ProjectState.from_apps()`. And that state is consistently using sets of tuples and not lists of lists. [^1]: https://github.com/django/django/commit/67dcea711e92025d0e8676b869b7ef15dbc6db73#diff-5dd147e9e978e645313dd99eab3a7bab1f1cb0a53e256843adb68aeed71e61dcR85-R87 [^2]: https://github.com/django/django/blob/b1ffa9a9d78b0c2c5ad6ed5a1d84e380d5cfd010/django/db/migrations/state.py#L842 [^3]: https://github.com/django/django/blob/b1ffa9a9d78b0c2c5ad6ed5a1d84e380d5cfd010/django/db/migrations/state.py#L340-L345 [^4]: https://github.com/django/django/blob/b1ffa9a9d78b0c2c5ad6ed5a1d84e380d5cfd010/django/db/migrations/autodetector.py#L1757-L1771 [^5]: https://github.com/django/django/blob/2351c1b12cc9cf82d642f769c774bc3ea0cc4006/django/core/management/commands/makemigrations.py#L215-L219 [^6]: https://github.com/django/django/blob/2351c1b12cc9cf82d642f769c774bc3ea0cc4006/django/core/management/commands/migrate.py#L329-L332
2026-01-19Fixed #36869 -- Optimized MigrationGraph._generate_plan membership checks.James Fysh
Previously, `_generate_plan()` relied on list membership checks, resulting in quadratic behavior as the plan grew. On large migration graphs this became a significant performance bottleneck. This change uses `OrderedSet` for the plan, reducing the complexity to linear while preserving insertion order and behavior. Co-authored-by: Nick Pope <nick@nickpope.me.uk>
2025-12-19Fixed #36791 -- Made MigrationAutodetector recreate through table when m2m ↵Johanan Oppong Amoateng
target model changes. Co-Authored-By: Jacob Walls <38668450+jacobtylerwalls@users.noreply.github.com> Co-Authored-By: Clifford Gama <cliffygamy@gmail.com>
2025-11-18Fixed #36141 -- Checked for applied replaced migrations recursively.Georgi Yanchev
Regression in 64b1ac7292c72d3551b2ad70b2a78c8fe4af3249.
2025-11-04Fixed #36652 -- Increased determinism when loading migrations from disk.Jayden Kneller
Ordering still depends on pkgutil.iter_modules, which does not guarantee order, but at least now Django is not introducing additional indeterminism, causing CircularDependencyError to appear or not appear in some edge cases. Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
2025-11-03Fixed #36695 -- Fixed handling of parameterized generics in migration ↵Augusto Pontes
serialization. Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
2025-10-18Fixed #21961 -- Added support for database-level delete options for ForeignKey.Mariusz Felisiak
Thanks Simon Charette for pair programming. Co-authored-by: Nick Stefan <NickStefan12@gmail.com> Co-authored-by: Akash Kumar Sen <71623442+Akash-Kumar-Sen@users.noreply.github.com> Co-authored-by: Simon Charette <charette.s@gmail.com>
2025-09-19Refs #36438 -- Simplified retrieval of GeneratedField base fields in ↵Clifford Gama
migrations autodetector. This was creating an unusable Q object solely to call referenced_base_fields on it.
2025-07-25Refs #36438 -- Made FieldOperation.references_field() detect references in ↵Clifford Gama
GeneratedField.expression. Thanks to Simon Charette for the suggestion and review.
2025-07-25Fixed #36438 -- Made MigrationAutodetector remove generated fields before ↵Clifford Gama
their base fields. Thanks to Colton Saska for the report and to Simon Charette for the review.
2025-07-23Refs #36500 -- Rewrapped long docstrings and block comments via a script.django-bot
Rewrapped long docstrings and block comments to 79 characters + newline using script from https://github.com/medmunds/autofix-w505.
2025-07-23Refs #36500 -- Shortened some long docstrings and comments.Mike Edmunds
Manually reformatted some long docstrings and comments that would be damaged by the to-be-applied autofixer script, in cases where editorial judgment seemed necessary for style or wording changes.
2025-07-03Refs #27236 -- Removed references to removed index_together migration methods.Clifford Gama
2025-06-27Fixed #35595, #35962 -- Removed indexes and constraints before fields in ↵wookkl
migrations.
2025-06-23Fixed #35305 -- Avoided recreating constraints on fields renamed via db_column.Jacob Walls
2025-06-19Refs #35038 -- Reduced CreateModel/AlterConstraint operations when ↵Jacob Walls
optimizing migrations.
2025-05-13Fixed #36383 -- Improved migration serialization for functools.partial objects.Adam Johnson
2025-05-13Refs #36383 -- Extended DeconstructibleSerializer to support non-identifier ↵Adam Johnson
keyword arguments. In Python, keyword arguments must normally be valid identifiers (i.e., variable names that follow Python's naming rules). However, Python dicts can have keys that aren't valid identifiers, like "foo-bar" or "123foo". This commit ensures that keyword arguments that are nt valid identifiers, are properly handled when deconstructing an object.
2025-05-13Refs #36383, #26151 -- Corrected spelling of DeconstructibleSerializer.Adam Johnson
"Deconstructible" is the spelling that Django has settled on, such as for `django.utils.deconstruct`. This commit normalizes a previously-inconsistent class to match the rest of the codebase.
2025-05-12Fixed #33174 -- Fixed migrations crash for model inheriting from Generic[T].Thibaut Decombe
2025-04-16Americanized some spellings.Adam Johnson
2025-04-16Fixed #36274 -- Added support for run_before and atomic in MigrationWriter.Mikuláš Poul
2025-04-01Fixed #36184 -- Allowed migrating forward to squashed migrations.Jacob Walls
2025-03-31Refs #28909 -- Simplified code using unpacking generalizations.Aarni Koskela
2025-03-31Fixed #36265 -- Added support for serialization of ZoneInfo instances in ↵Song Junho
migrations.
2025-02-18Refs #36005 -- Used datetime.UTC alias instead of datetime.timezone.utc.Mariusz Felisiak
datetime.UTC was added in Python 3.11.
2025-02-16Refs #35704 -- Used copy.replace() in Operation.reduce() methods.Adam Johnson
2025-02-13Fixed #36146 -- Recorded applied/unapplied migrations recursively.Georgi Yanchev
2025-02-06Refs #22997 -- Prevented requesting a default value for auto fields.Ben Cail
2025-01-22Fixed #24529 -- Allowed double squashing of migrations.Georgi Yanchev
Co-authored-by: Raphael Gaschignard <raphael@rtpg.co>
2025-01-22Refs #24529 -- Added replace_migration hook to MigrationLoader.Georgi Yanchev
2025-01-20Fixed #36005 -- Dropped support for Python 3.10 and 3.11.Mariusz Felisiak
2025-01-10Refs #36064 -- Added Model.has_db_default() to encapsulate NOT_PROVIDED checks.Simon Charette
This avoids many awkward checks against NOT_PROVIDED and provides symmetry with Field.has_default() which is also the reason why it wasn't made a property.
2024-12-27Fixed #35991 -- Fixed crash when adding non-nullable field after renaming ↵Mariusz Felisiak
part of CompositePrimaryKey on SQLite.
2024-12-19Fixed #36016 -- Prevented traceback when quitting makemigrations with Ctrl-C.Aman Sharma
2024-12-17Fixed #34856 -- Fixed references to index_together in historical migrations.Andrés Reverón Molina
While AlterUniqueTogether has been documented to be still allowed in historical migrations for the foreseeable future it has been crashing since 2abf417c815c20 was merged because the latter removed support for Meta.index_together which the migration framework uses to render models to perform schema changes. CreateModel(options["unique_together"]) was also affected. Refs #27236. Co-authored-by: Simon Charette <charette.s@gmail.com>
2024-12-17Refs #27236 -- Removed references to index_together from ModelState.from_model.Simon Charette
It's not possible for ModelMeta.index_together to exist anymore.
2024-11-28Fixed #35038 -- Created AlterConstraint operation.Salvo Polizzi
2024-11-18Fixed #35882 -- Made migration questioner loop on all errors.Adam Johnson
2024-09-03Fixed #35704 -- Fixed reduction for AddIndex subclasses.Adam Johnson
2024-08-30Fixed #35700 -- Added AlterModelTable and AlterModelTableComment reductions.Adam Johnson
2024-07-10Fixed #35424 -- Checked order_with_respect_to is available when migrating ↵Daniel Patrick
_order fields. Migrations would crash following the removal of an order_with_respect_to field from a model and the addition of an _order field.
2024-06-13Fixed #34881 -- Fixed a crash when renaming a model with multiple ↵Anže Pečar
ManyToManyField.through references on SQLite. Thank you to dennisvang for the report and Jase Hackman for the test. Co-authored-by: Jase Hackman <jase.hackman@zapier.com>
2024-05-02Fixed #35359 -- Fixed migration operations ordering when adding fields ↵DevilsAutumn
referenced by GeneratedField.expression. Thank you to Simon Charette for the review.
2024-03-22Fixed #34841 -- Avoided rendering apps on state still requiring mutation.David Sanders
2024-02-09Refs #34534 -- Reduced constraint operations with Meta.constraints when ↵Ben Cail
optimizing migrations.
2024-01-26Applied Black's 2024 stable style.Mariusz Felisiak
https://github.com/psf/black/releases/tag/24.1.0
2024-01-17Fixed #31700 -- Made makemigrations command display meaningful symbols for ↵Amir Karimi
each operation.