summaryrefslogtreecommitdiff
path: root/tests/migrations/test_operations.py
AgeCommit message (Collapse)Author
2026-02-10Added various missing test skips observed on MongoDB.Tim Graham
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
2025-12-13Fixed #36765 -- Added support for stored GeneratedFields on Oracle 23ai/26ai ↵Mariusz Felisiak
(23.7+). Thanks Jacob Walls for the review.
2025-08-04Fixed #35972 -- Fixed lookup crashes after subquery annotations.Jacob Walls
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-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-03-09Fixed #35487 -- Removed CASCADE from RemoveField() on PostgreSQL.petr.prikryl
Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com> Co-authored-by: Adam Johnson <me@adamj.eu> Co-authored-by: Sarah Boyce <42296566+sarahboyce@users.noreply.github.com>
2025-01-13Refs #373 -- Adjusted test allowing AutoField in composite primary keys.Simon Charette
This is not a properly supported feature yet and should be revisited by refs #35957.
2024-12-27Fixed #35991 -- Fixed crash when adding non-nullable field after renaming ↵Mariusz Felisiak
part of CompositePrimaryKey on SQLite.
2024-12-17Fixed #35969 -- Disallowed specifying a USING clause for altered generated ↵lufafajoshua
field. PostgreSQL versions 16.5 and above no longer permit the use of a USING clause when changing the type of a generated column.
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-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-08-01Reverted "Fixed #28646 -- Prevented duplicate index when unique is set to ↵Sarah Boyce
True on PostgreSQL." This reverts commit 9cf9c796be8dd53bc3b11355ff39d65c81d7be6d due to a crash on Oracle as it didn't allow multiple indexes on the same field.
2024-07-30Fixed #28646 -- Prevented duplicate index when unique is set to True on ↵Ben Cail
PostgreSQL.
2024-07-25Fixed #35625 -- Fixed a crash when adding a field with db_default and check ↵Simon Charette
constraint. This is the exact same issue as refs #30408 but for creating a model with a constraint containing % escapes instead of column addition. All of these issues stem from a lack of SQL and parameters separation from the BaseConstraint DDL generating methods preventing them from being mixed with other parts of the schema alteration logic that do make use of parametrization on some backends (e.g. Postgres, MySQL for DEFAULT). Prior to the addition of Field.db_default and GeneratedField in 5.0 parametrization of DDL was never exercised on model creation so this is effectively a bug with db_default as the GeneratedField case was addressed by refs #35336. Thanks Julien Chaumont for the report and Mariusz Felisiak for the review.
2024-06-14Refs #34881 -- Fixed ↵Mariusz Felisiak
OperationTests.test_rename_m2m_field_with_2_references() test on Oracle.
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-23Fixed typo in migrations test name.Tim Graham
2024-05-03Fixed #35422 -- Fixed migrations crash when altering GeneratedField ↵Mariusz Felisiak
referencing rename field. Thanks Sarah Boyce for the report and Simon Charette for the implementation idea.
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-25Increased test coverage for django.db.migrations.operations.special.Mariusz Felisiak
2024-03-14Fixed #28541 -- Fixed migrations crash when changing primary key on SQLite.Ben Cail
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-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.
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.
2023-12-22Fixed #35022 -- Fixed RenameIndex() crash on unnamed indexes if exists ↵David Wobrock
unique constraint on the same fields.
2023-11-22Fixed #34984 -- Skipped GeneratedFields when remaking tables on SQLite.Sarah Boyce
Regression in f333e3513e8bdf5ffeb6eeb63021c230082e6f95.t Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com> Co-authored-by: David Sanders <shang.xiao.sanders@gmail.com>
2023-11-14Fixed #34944 -- Made GeneratedField.output_field required.Mariusz Felisiak
Regression in f333e3513e8bdf5ffeb6eeb63021c230082e6f95.
2023-11-07Fixed #34946 -- Preserved db_default on combined default field addition.Simon Charette
Regression in 7414704e88d73dafbcfbb85f9bc54cb6111439d3.
2023-11-02Refs #34936 -- Added test for altering DecimalField with db_default to ↵David Sanders
non-nullable.
2023-09-18Refs #27236 -- Removed Meta.index_together per deprecation timeline.Mariusz Felisiak
2023-09-09Fixed #34820 -- Fixed migrations crash when changing a ForeignObject field.donghao
2023-09-07Fixed #31300 -- Added GeneratedField model field.Jeremy Nauta
Thanks Adam Johnson and Paolo Melchiorre for reviews. Co-Authored-By: Lily Foote <code@lilyf.org> Co-Authored-By: Mariusz Felisiak <felisiak.mariusz@gmail.com>
2023-08-04Fixed #34760 -- Dropped support for SQLite < 3.27.Mariusz Felisiak
2023-07-22Refs #24686 -- Made AlterField operation a noop when renaming related model ↵devilsautumn
with db_table.
2023-07-18Refs #33201 -- Avoided unnecessary queries when renaming models with ↵Mariusz Felisiak
db_table on SpatiaLite.
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-10Fixed #34553 -- Fixed improper % escaping of literal in constraints.Simon Charette
Proper escaping of % in string literals used when defining constaints was attempted (a8b3f96f6) by overriding quote_value of Postgres and Oracle schema editor. The same approach was used when adding support for constraints to the MySQL/MariaDB backend (1fc2c70). Later on it was discovered that this approach was not appropriate and that a preferable one was to pass params=None when executing the constraint creation DDL to avoid any form of interpolation in the first place (42e8cf47). When the second patch was applied the corrective of the first were not removed which caused % literals to be unnecessary doubled. This flew under the radar because the existings test were crafted in a way that consecutive %% didn't catch regressions. This commit introduces an extra test for __exact lookups which highlights more adequately % doubling problems but also adjust a previous __endswith test to cover % doubling problems (%\% -> %%\%%). Thanks Thomas Kolar for the report. Refs #32369, #30408, #30593.
2023-05-10Refs #34553 -- Split constraint escaping test in subtests.Simon Charette
This ensures that constraint violations are tested in isolation from each other as an IntegrityError only ensures a least one constraint is violated. For example, the assertion added in 42e8cf4 break both the name_constraint_rhs and the rebate_constraint constraints and thus doesn't constitute a proper regression test. Refs #32369.
2023-02-23Refs #30060, Refs #34217 -- Made SchemaEditor not generate SQL for ↵Mariusz Felisiak
CheckConstraint if not supported. The new logic mirrors the logic in SchemaEditor._delete_check_sql() added in 68ef274bc505cd44f305c03cbf84cf08826200a8. Thanks Tim Graham for the report.
2023-02-14Fixed #34250 -- Fixed renaming model with m2m relation to a model with the ↵DevilsAutumn
same name.
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-12-27Fixed #34217 -- Fixed migration crash when removing check constraints on ↵DevilsAutumn
MySQL < 8.0.16.
2022-11-17Fixed #28987 -- Fixed altering ManyToManyField when changing to ↵DevilsAutumn
self-referential.
2022-09-25Fixed #34027 -- Fixed migrations crash when altering type of char/text ↵David Sanders
fields referenced by foreign key on PostgreSQL.
2022-08-29Refs #33953 -- Fixed test_rename_model_with_db_table_rename_m2m() crash on ↵Mariusz Felisiak
SQLite < 3.20.