mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Fixed #23609 -- Fixed IntegrityError that prevented altering a NULL column into a NOT NULL one due to existing rows
Thanks to Simon Charette, Loic Bistuer and Tim Graham for the review.
This commit is contained in:
parent
15d350fbce
commit
f633ba778d
9 changed files with 256 additions and 36 deletions
|
@ -137,7 +137,7 @@ or if it is temporary and just for this migration (``False``) - usually
|
|||
because the migration is adding a non-nullable field to a table and needs
|
||||
a default value to put into existing rows. It does not effect the behavior
|
||||
of setting defaults in the database directly - Django never sets database
|
||||
defaults, and always applies them in the Django ORM code.
|
||||
defaults and always applies them in the Django ORM code.
|
||||
|
||||
RemoveField
|
||||
-----------
|
||||
|
@ -153,16 +153,28 @@ from any data loss, which of course is irreversible).
|
|||
AlterField
|
||||
----------
|
||||
|
||||
.. class:: AlterField(model_name, name, field)
|
||||
.. class:: AlterField(model_name, name, field, preserve_default=True)
|
||||
|
||||
Alters a field's definition, including changes to its type,
|
||||
:attr:`~django.db.models.Field.null`, :attr:`~django.db.models.Field.unique`,
|
||||
:attr:`~django.db.models.Field.db_column` and other field attributes.
|
||||
|
||||
The ``preserve_default`` argument indicates whether the field's default
|
||||
value is permanent and should be baked into the project state (``True``),
|
||||
or if it is temporary and just for this migration (``False``) - usually
|
||||
because the migration is altering a nullable field to a non-nullable one and
|
||||
needs a default value to put into existing rows. It does not effect the
|
||||
behavior of setting defaults in the database directly - Django never sets
|
||||
database defaults and always applies them in the Django ORM code.
|
||||
|
||||
Note that not all changes are possible on all databases - for example, you
|
||||
cannot change a text-type field like ``models.TextField()`` into a number-type
|
||||
field like ``models.IntegerField()`` on most databases.
|
||||
|
||||
.. versionchanged:: 1.7.1
|
||||
|
||||
The ``preserve_default`` argument was added.
|
||||
|
||||
RenameField
|
||||
-----------
|
||||
|
||||
|
|
|
@ -106,3 +106,7 @@ Bugfixes
|
|||
|
||||
* Made :func:`~django.utils.http.urlsafe_base64_decode` return the proper
|
||||
type (byte string) on Python 3 (:ticket:`23333`).
|
||||
|
||||
* Added a prompt to the migrations questioner when removing the null constraint
|
||||
from a field to prevent an IntegrityError on existing NULL rows
|
||||
(:ticket:`23609`).
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue