summaryrefslogtreecommitdiff
path: root/tests/migrations/test_autodetector.py
AgeCommit message (Collapse)Author
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
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-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-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-02-06Refs #22997 -- Prevented requesting a default value for auto fields.Ben Cail
2024-11-29Fixed #373 -- Added CompositePrimaryKey.Bendeguz Csirmaz
Thanks Lily Foote and Simon Charette for reviews and mentoring this Google Summer of Code 2024 project. Co-authored-by: Simon Charette <charette.s@gmail.com> Co-authored-by: Lily Foote <code@lilyf.org>
2024-11-28Fixed #35038 -- Created AlterConstraint operation.Salvo Polizzi
2024-11-28Refs #35038 -- Added test for drop and recreation of a constraint.Salvo Polizzi
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-01Refs #35234 -- Deprecated CheckConstraint.check in favor of .condition.Simon Charette
Once the deprecation period ends CheckConstraint.check() can become the documented method that performs system checks for BaseConstraint subclasses.
2024-02-09Refs #34534 -- Reduced constraint operations with Meta.constraints when ↵Ben Cail
optimizing migrations.
2024-02-04Fixed #35149 -- Fixed crashes of db_default with unresolvable output field.Simon Charette
Field.db_default accepts either literal Python values or compilables (as_sql) and wrap the former ones in Value internally. While 1e38f11 added support for automatic resolving of output fields for types such as str, int, float, and other unambigous ones it's cannot do so for all types such as dict or even contrib.postgres and contrib.gis primitives. When a literal, non-compilable, value is provided it likely make the most sense to bind its output field to the field its attached to avoid forcing the user to provide an explicit `Value(output_field)`. Thanks David Sanders for the report.
2023-09-18Refs #27236 -- Removed Meta.index_together per deprecation timeline.Mariusz Felisiak
2023-09-11Fixed #34824 -- Prevented unnecessary AlterField when ↵donghao
ForeignObject.from_fields/to_fields is not a tuple.
2023-08-23Fixed #34744 -- Prevented recreation of migration for constraints with a ↵David Sanders
dict_keys. Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
2023-05-12Fixed #470 -- Added support for database defaults on fields.Ian Foote
Special thanks to Hannes Ljungberg for finding multiple implementation gaps. Thanks also to Simon Charette, Adam Johnson, and Mariusz Felisiak for reviews.
2023-05-03Fixed #34529, Refs #34525 -- Reduced index operations with ↵Mariusz Felisiak
Meta.indexes/index_together when optimizing migrations. This makes squashing migrations an available path for changing Meta.index_together, which is deprecated, to Meta.indexes. Follow up to f81032572107846922745b68d5b7191058fdd5f5.
2023-03-10Fixed #34333 -- Fixed migration operations ordering when adding ↵Durval Carvalho
index/constraint on new foreign key. Thanks Simon Charette and David Wobrock for reviews.
2023-01-19Fixed #32528 -- Replaced django.utils.topological_sort with ↵Nick Pope
graphlib.TopologicalSort(). graphlib.TopologicalSort() is available since Python 3.9.
2022-12-28Fixed #18468 -- Added support for comments on columns and tables.kimsoungryoul
Thanks Jared Chung, Tom Carrick, David Smith, Nick Pope, and Mariusz Felisiak for reviews. Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com> Co-authored-by: Nick Pope <nick@nickpope.me.uk>
2022-09-27Fixed #34050 -- Replaced invalid chars in migration names with '_'.Adam Johnson
Thanks to Bishal Gautam for the report and initial implementation. Regression in fa58450a9ab8a1bdd2a5090b51b00078fd85ffa6. Co-Authored-By: Bishal Gautam <bisalgt@gmail.com>
2022-08-25Fixed #33938 -- Fixed migration crash for m2m with a through model in ↵Simon Charette
another app. Regression in aa4acc164d1247c0de515c959f7b09648b57dc42. Thanks bryangeplant for the report.
2022-07-12Fixed #27236 -- Deprecated Meta.index_together in favor of Meta.indexes.David Wobrock
This also deprecates AlterIndexTogether migration operation.
2022-06-13Refs #27236 -- Split index_together and unique_together autodetector tests.David Wobrock
2022-06-13Refs #27236 -- Added test_autodetector.BaseAutodetectorTests.David Wobrock
2022-06-02Fixed #31788 -- Fixed migration optimization after altering field to ↵David Wobrock
ManyToManyField. This makes AddField() used for altering to ManyToManyField, dependent on the prior RemoveField.
2022-05-17Refs #27064 -- Made migrations generate RenameIndex operations when moving ↵David Wobrock
indexes from index_together to Meta.indexes.
2022-05-16Refs #27064 -- Made migrations generate RenameIndex operations when renaming ↵David Wobrock
Meta.indexes.
2022-04-04Fixed #33605 -- Fixed migration crash when altering RegexValidator to ↵Brian Helba
pre-compiled regular expression.
2022-02-16Fixed #33515 -- Prevented recreation of migration for ManyToManyField to ↵Mariusz Felisiak
lowercased swappable setting. Thanks Chris Lee for the report. Regression in 43289707809c814a70f0db38ca4f82f35f43dbfd. Refs #23916.
2022-02-07Refs #33476 -- Refactored code to strictly match 88 characters line length.Mariusz Felisiak
2022-02-07Refs #33476 -- Reformatted code with Black.django-bot
2022-02-01Fixed #33480 -- Fixed makemigrations crash when renaming field of renamed model.Kirill Safronov
Regression in aa4acc164d1247c0de515c959f7b09648b57dc42.
2022-01-04Fixed #33402 -- Optimized multiple AlterFooTogether operations.David Wobrock
2021-12-17Fixed #33366 -- Fixed case handling with swappable setting detection in ↵Simon Charette
migrations autodetector. The migration framework uniquely identifies models by case insensitive labels composed of their app label and model names and so does the app registry in most of its methods (e.g. AppConfig.get_model) but it wasn't the case for get_swappable_settings_name() until this change. This likely slipped under the radar for so long and only regressed in b9df2b74b98b4d63933e8061d3cfc1f6f39eb747 because prior to the changes related to the usage of model states instead of rendered models in the auto-detector the exact value settings value was never going through a case folding hoop. Thanks Andrew Chen Wang for the report and Keryn Knight for the investigation.
2021-11-22Fixed #33305 -- Fixed autodetector crash for ForeignKey with hardcoded "to" ↵Baptiste Mispelon
attribute. Co-authored-by: Simon Charette <charette.s@gmail.com>
2021-11-02Fixed #33234 -- Fixed autodetector crash for proxy models inheriting from ↵Mariusz Felisiak
non-model class. Regression in aa4acc164d1247c0de515c959f7b09648b57dc42. Thanks Kevin Marsh for the report.
2021-10-26Corrected AutodetectorTests.test_rename_field_and_foo_together()'s docstring.Mariusz Felisiak
2021-10-25Fixed #31503 -- Made autodetector remove unique/index_together before ↵David Wobrock
altering fields.
2021-10-19Fixed #33197 -- Made field rename with prior matching db_column change a noop.Simon Charette
Thanks Jacob Walls for the report.
2021-10-15Fixed #23953 -- Made makemigrations continue number sequence for squashed ↵Jacob Walls
migrations.
2021-10-15Refs #23953 -- Added MigrationAutodetector.parse_number() tests.Jacob Walls
2021-09-20Refs #33119 -- Added tests for changing model name case referenced by ↵AliGhotbizadeh
ManyToManyField. Fixed in aa4acc164d1247c0de515c959f7b09648b57dc42.
2021-08-11Refs #29898 -- Changed ProjectState.real_apps to set.Mariusz Felisiak
2021-04-16Fixed #29899 -- Made autodetector use model states instead of model classes.David Wobrock
Thanks Simon Charette and Markus Holtermann for reviews.
2021-03-12Fixed #31516 -- Improved naming of migrations with multiple operations.manav014
52 gives 60 in total (52 + 5 + 3). Co-authored-by: Adam Johnson <me@adamj.eu>
2021-03-12Refs #31516 -- Added Migration.suggest_name() tests for migrations with no ↵Adam Johnson
operations.
2021-03-12Refs #31516, Refs #31703 -- Made makemigrations always name initial ↵Adam Johnson
migrations "initial".