Opened 9 years ago

Closed 9 years ago

#25906 closed Bug (duplicate)

`squashmigrations` generates migrations that don't work with Python 3

Reported by: Patryk Zawadzki Owned by: nobody
Component: Migrations Version: 1.9
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When I run squashmigrations I get something similar to the following:

class Migration(migrations.Migration):

    replaces = [(b'registration', '0001_initial'), (b'registration', '0002_auto_20151203_1158')]
    ...

Notice how app names are passed as bytes instances.

Now in Python 3 a bytes objects is never equal to its Unicode (str) representation. This inequality makes Django consider the squashed migration conflicting with the migrations it replaces.

Change History (3)

comment:1 by Tim Graham, 9 years ago

It's another case of #24949 (we could coerce the app_name bytestring), but an alternative is to add from __future__ import unicode_literals to the apps.py in the project template as we do for other files. I think the latter solution could be backported to 1.9. Should we create a separate ticket for that and close this as a duplicate of #24949?

comment:2 by Patryk Zawadzki, 9 years ago

I don't think changing the project template will help anyone who faces this problem as it means they already have a settings file. IMO Django should tell users to fix their settings and refuse to create broken migrations.

comment:3 by Tim Graham, 9 years ago

Resolution: duplicate
Status: newclosed

We have the same problem (bytes/unicode discrepancy) in other places since Django 1.7 and another solution has been proposed in #24949 so I'll add a note about this there and mark this as a duplicate. We don't know whether or not a user intends migrations to work on both Python 2 and 3, so starting to throw errors when it's not really an error could be annoying. If you disagree with the solution proposed in #24949, could you leave a comment there?

I created #25909 for the unicode_literals proposal.

Thanks for raising the issue!

Note: See TracTickets for help on using tickets.
Back to Top