summaryrefslogtreecommitdiff
path: root/django/db/backends/base/schema.py
AgeCommit message (Collapse)Author
2025-12-22Fixed typo in django/db/backends/base/schema.py comment.사재혁
Signed-off-by: JaeHyuck Sa <wogur981208@gmail.com>
2025-12-16Fixed #36800 -- Restored ManyToManyField renaming in ↵Clifford Gama
BaseDatabaseSchemaEditor.alter_field(). Regression in f9a44cc0fac653f8e0c2ab1cdfb12b2cc5c63fc2. Now that ManyToManyField is no longer concrete the decision of whether or not it should be altered, which is also relied on by field renaming, should take into consideration name changes even if it doesn't have a column associated with it, as auto-created many-to-many relationship table names are a base of it. Note that there is room for optimization here where a rename can be entirely avoided if ManyToManyField.db_table remains stable between .name changes, just like we do with Field.db_column remaining stable, but since this is a regression and meant to be backported the current patch focuses on correctness over further improvements. Thanks Josik for the report. Co-authored-by: Simon Charette <charette.s@gmail.com>
2025-12-13Fixed #36765 -- Added support for stored GeneratedFields on Oracle 23ai/26ai ↵Mariusz Felisiak
(23.7+). Thanks Jacob Walls for the review.
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-22Fixed #35453 -- Made ManyToManyField.concrete False.Ryan P Kilby
ManyToManyField was already excluded from fields, concrete_fields, and local_concrete_fields in Options.
2025-08-04Fixed #35972 -- Fixed lookup crashes after subquery annotations.Jacob Walls
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-02-22Fixed #35839 -- Fixed crash when adding GeneratedField with db_comment on MySQL.saJaeHyukc
Thanks Simon Charette for the test. Signed-off-by: saJaeHyukc <wogur981208@gmail.com>
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-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-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-05-28Fixed #35469 -- Removed deferred SQL to create index removed by AlterField ↵Jacob Walls
operation.
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-04-02Fixed #35336 -- Addressed crash when adding a GeneratedField with % literals.Simon Charette
A longer term solution is likely to have a better separation of parametrized DDL altogether to handle checks, constraints, defaults, and generated fields but such a change would require a significant refactor that isn't suitable for a backport. Thanks Adrian Garcia for the report.
2024-03-26Fixed #35329 -- Fixed migrations crash when adding partial unique ↵Mariusz Felisiak
constraints with nulls_distinct. Bug in 595a2abb58e04caa4d55fb2589bb80fb2a8fdfa1. Thanks Lucas Lemke Saunitti for the report.
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-02-04Refs #35149 -- Made equivalent db_default alterations noops.Simon Charette
This allows for an easier transition of preserving the literal nature of non-compilable db_default.
2024-02-03Fixed #35162 -- Fixed crash when adding fields with db_default on MySQL.Simon Charette
MySQL doesn't allow literal DEFAULT values to be used for BLOB, TEXT, GEOMETRY or JSON columns and requires expression to be used instead. Regression in 7414704e88d73dafbcfbb85f9bc54cb6111439d3.
2024-01-26Applied Black's 2024 stable style.Mariusz Felisiak
https://github.com/psf/black/releases/tag/24.1.0
2023-12-03Fixed #35002 -- Made UniqueConstraints with fields respect nulls_distinct.Peter Thomassen
Regression in 595a2abb58e04caa4d55fb2589bb80fb2a8fdfa1.
2023-11-30Fixed #35006 -- Fixed migrations crash when altering Meta.db_table_comment ↵Mariusz Felisiak
on SQLite. Thanks Юрий for the report. Regression in 78f163a4fb3937aca2e71786fbdd51a0ef39629e.
2023-11-07Fixed #34946 -- Preserved db_default on combined default field addition.Simon Charette
Regression in 7414704e88d73dafbcfbb85f9bc54cb6111439d3.
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-07-22Refs #24686 -- Made AlterField operation a noop when renaming related model ↵devilsautumn
with db_table.
2023-07-19Fixed #34701 -- Added support for NULLS [NOT] DISTINCT on PostgreSQL 15+.Simon Charette
2023-07-19Reduced unique constraint eligibility code duplication.Simon Charette
2023-06-23Improved style of n-tuple wording in docs and comments.Nick Pope
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-05Refs #27236 -- Made more cosmetic edits to Meta.index_together deprecation.Mariusz Felisiak
2023-03-02Refs #34320 -- Stopped recreating check constraints when renaming fields.Mariusz Felisiak
This also fixes test_rename_field_with_check_to_truncated_name() on MariaDB 10.5.2+ as ALTER TABLE ... RENAME COLUMN statement doesn't rename inline constraints.
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-15Fixed #34320 -- Make sure constraints names are obtained from truncated ↵nabil-rady
columns names.
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-12-22Fixed #34219 -- Preserved Char/TextField.db_collation when altering column type.Mariusz Felisiak
This moves setting a database collation to the column type alteration as both must be set at the same time. This should also avoid another layer of the column type alteration when adding database comments support (#18468).
2022-10-31Used more augmented assignment statements.Nick Pope
Identified using the following command: $ git grep -I '\(\<[_a-zA-Z0-9]\+\>\) *= *\1 *[-+/*^%&|<>@]'
2022-09-07Fixed #33982 -- Fixed migrations crash when adding model with ↵James Beith
ExclusionConstraint. Regression in 0e656c02fe945389246f0c08f51c6db4a0849bd2.
2022-08-12Fixed #33919 -- Fixed adding AutoFields on PostgreSQL.Mariusz Felisiak
Thanks Jack Calvin Brown for the report. Regression in 2eea361eff58dd98c409c5227064b901f41bd0d6.
2022-08-02Fixed #33881 -- Added support for database collations to ↵Mariusz Felisiak
ArrayField(Char/TextFields).
2022-06-13Fixed #33773 -- Made Index with multiple fields respect ↵Bruce Cutler
DEFAULT_INDEX_TABLESPACE. Thanks to Simon Charette for locating where issue lay.
2022-05-26Fixed #23740 -- Fixed removing unique_together constraint if exists primary ↵David Wobrock
key/unique constraint on the same field.
2022-05-26Refs #23740 -- Added BaseDatabaseSchemaEditor._unique_constraint_name().David Wobrock
2022-05-12Refs #27064 -- Added RenameIndex migration operation.David Wobrock
2022-05-03Fixed #29854 -- Made _all_related_fields() return deterministically ordered ↵Collin Anderson
fields. Thanks to Rick Yang and Baptiste Mispelon for the investigation.