mirror of
https://github.com/django/django.git
synced 2025-06-05 03:29:12 +00:00
Fixed #24690 -- Added a warning about mutable defaults for ArrayField/JSONField.
This commit is contained in:
parent
fd81588bc6
commit
f93e7f5674
@ -17,6 +17,12 @@ ArrayField
|
|||||||
<ArrayField.size>`. ``ArrayField`` can be nested to store multi-dimensional
|
<ArrayField.size>`. ``ArrayField`` can be nested to store multi-dimensional
|
||||||
arrays.
|
arrays.
|
||||||
|
|
||||||
|
If you give the field a :attr:`~django.db.models.Field.default`, ensure
|
||||||
|
it's a callable such as ``list`` (for an empty default) or a callable that
|
||||||
|
returns a list (such as a function). Incorrectly using ``default=[]``
|
||||||
|
creates a mutable default that is shared between all instances of
|
||||||
|
``ArrayField``.
|
||||||
|
|
||||||
.. attribute:: base_field
|
.. attribute:: base_field
|
||||||
|
|
||||||
This is a required argument.
|
This is a required argument.
|
||||||
@ -461,6 +467,12 @@ JSONField
|
|||||||
its Python native format: dictionaries, lists, strings, numbers, booleans
|
its Python native format: dictionaries, lists, strings, numbers, booleans
|
||||||
and ``None``.
|
and ``None``.
|
||||||
|
|
||||||
|
If you give the field a :attr:`~django.db.models.Field.default`, ensure
|
||||||
|
it's a callable such as ``dict`` (for an empty default) or a callable that
|
||||||
|
returns a dict (such as a function). Incorrectly using ``default={}``
|
||||||
|
creates a mutable default that is shared between all instances of
|
||||||
|
``JSONField``.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
PostgreSQL has two native JSON based data types: ``json`` and ``jsonb``.
|
PostgreSQL has two native JSON based data types: ``json`` and ``jsonb``.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user