mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Fixed #8802 -- Documented MySQL's usage of 1/0 instead of True/False for model
BooleanFields. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8910 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
fd78e89d1e
commit
fd1d986bb1
2 changed files with 23 additions and 0 deletions
|
@ -296,6 +296,19 @@ A true/false field.
|
|||
|
||||
The admin represents this as a checkbox.
|
||||
|
||||
.. admonition:: MySQL users..
|
||||
|
||||
A boolean field in MySQL is stored as a ``TINYINT`` column with a value of
|
||||
either 0 or 1 (most databases have a proper ``BOOLEAN`` type instead). So,
|
||||
for MySQL, only, when a ``BooleanField`` is retrieved from the database
|
||||
and stored on a model attribute, it will have the values 1 or 0, rather
|
||||
than ``True`` or ``False``. Normally, this shouldn't be a problem, since
|
||||
Python guarantees that ``1 == True`` and ``0 == False`` are both true.
|
||||
Just be careful if you're writing something like ``obj is True`` when
|
||||
``obj`` is a value from a boolean attribute on a model. If that model was
|
||||
constructed using the ``mysql`` backend, the "``is``" test will fail.
|
||||
Prefer an equality test (using "``==``") in cases like this.
|
||||
|
||||
``CharField``
|
||||
-------------
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue