Skip to content

Commit d4bddde

Browse files
committed
Fixed #23982 -- Added doc note on generating Python 2/3 cross-compatible migrations.
Thanks Luke Plant for the report, and Tim Graham, Simon Charette, and Markus Holtermann for review and discussion.
1 parent 8aaf51f commit d4bddde

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

docs/topics/migrations.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,26 @@ The decorator adds logic to capture and preserve the arguments on their
638638
way into your constructor, and then returns those arguments exactly when
639639
deconstruct() is called.
640640

641+
Supporting Python 2 and 3
642+
-------------------------
643+
644+
In order to generate migrations that support both Python 2 and 3, all string
645+
literals used in your models and fields (e.g. ``verbose_name``,
646+
``related_name``, etc.), must be consistently either bytestrings or text
647+
(unicode) strings in both Python 2 and 3 (rather than bytes in Python 2 and
648+
text in Python 3, the default situation for unmarked string literals.)
649+
Otherwise running :djadmin:`makemigrations` under Python 3 will generate
650+
spurious new migrations to convert all these string attributes to text.
651+
652+
The easiest way to achieve this is to follow the advice in Django's
653+
:doc:`Python 3 porting guide </topics/python3>` and make sure that all your
654+
modules begin with ``from __future__ import unicode_literals``, so that all
655+
unmarked string literals are always unicode, regardless of Python version. When
656+
you add this to an app with existing migrations generated on Python 2, your
657+
next run of :djadmin:`makemigrations` on Python 3 will likely generate many
658+
changes as it converts all the bytestring attributes to text strings; this is
659+
normal and should only happen once.
660+
641661
.. _upgrading-from-south:
642662

643663
Upgrading from South

0 commit comments

Comments
 (0)