Opened 10 years ago
Closed 9 years ago
#26385 closed Bug (wontfix)
Squashing migrations with Python 2.7 adds bytestring prefix to ManyToManyField 'to' values which fails to run on Python 3
| Reported by: | Brian May | Owned by: | nobody |
|---|---|---|---|
| Component: | Migrations | Version: | 1.9 |
| Severity: | Normal | Keywords: | py2 |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
In attempting a work around for #26384 by squashing the commits, I found another problem:
E AssertionError: ManyToManyField(b'spud.album') is invalid. First parameter to ManyToManyField must be either a model, a model name, or the string 'self'
I believe the problem is that it used a byte value instead of a string.
migrations.AddField(
model_name='photo',
name='albums',
field=models.ManyToManyField(related_name='photos', through='spud.photo_album', to=b'spud.album'),
),
This works fine with Python 2.7 but not with Python 3.4.
The original before squashing was ok:
migrations.AddField(
model_name='photo',
name='albums',
field=models.ManyToManyField(related_name='photos', through='spud.photo_album', to='spud.album'),
preserve_default=True,
),
Change History (5)
comment:2 by , 10 years ago
Looks like squashing the migration in Python3.4 creates a migration that will work with all versions of Python.
Curiously though with Python 2.7 it sets initial=True on the migration, but when squashed with Python3.4 it doesn't.
comment:3 by , 10 years ago
| Summary: | Squash migrations with Python 3.4 creates broken migrations → Squashing migrations with Python 2.7 adds bytestring prefix to ManyToManyField 'to' values which fails to run on Python 3 |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
I can reproduce the issue but cannot track where the bytestring is coming from. A more minimal sample project may help but I think the issue isn't high priority since Python 2 support will be dropped soon.
comment:4 by , 9 years ago
| Keywords: | py2 added |
|---|
comment:5 by , 9 years ago
| Resolution: | → wontfix |
|---|---|
| Status: | new → closed |
Closing given Python 2 support will be dropped in master in a couple weeks.
Forgot to mention, the squashed commits were created with Python 2.7