mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Fixed #24591 -- Optimized cloning of ModelState objects.
Changed ModelState.clone() to create a shallow copy of self.fields and self.managers.
This commit is contained in:
parent
c331eeb89c
commit
1a1f16d67d
3 changed files with 42 additions and 4 deletions
|
@ -402,7 +402,8 @@ You can take this template and work from it, though we suggest looking at the
|
|||
built-in Django operations in ``django.db.migrations.operations`` - they're
|
||||
easy to read and cover a lot of the example usage of semi-internal aspects
|
||||
of the migration framework like ``ProjectState`` and the patterns used to get
|
||||
historical models.
|
||||
historical models, as well as ``ModelState`` and the patterns used to mutate
|
||||
historical models in ``state_forwards()``.
|
||||
|
||||
Some things to note:
|
||||
|
||||
|
@ -421,6 +422,16 @@ Some things to note:
|
|||
operations; this is part of the autodetection code and does not matter for
|
||||
custom operations.
|
||||
|
||||
.. warning::
|
||||
|
||||
For performance reasons, the :class:`~django.db.models.Field` instances in
|
||||
``ModelState.fields`` are reused across migrations. You must never change
|
||||
the attributes on these instances. If you need to mutate a field in
|
||||
``state_forwards()``, you must remove the old instance from
|
||||
``ModelState.fields`` and add a new instance in its place. The same is true
|
||||
for the :class:`~django.db.models.Manager` instances in
|
||||
``ModelState.managers``.
|
||||
|
||||
As a simple example, let's make an operation that loads PostgreSQL extensions
|
||||
(which contain some of PostgreSQL's more exciting features). It's simple enough;
|
||||
there's no model state changes, and all it does is run one command::
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue