Opened 9 years ago
Closed 9 years ago
#27717 closed Cleanup/optimization (fixed)
Squashmigrations doesn't optimize AlterModelOptions verbose_name_plural into CreateModel
| Reported by: | Ed Morley | Owned by: | Ed Morley |
|---|---|---|---|
| Component: | Migrations | Version: | dev |
| Severity: | Normal | Keywords: | squashmigrations |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
The squashmigrations command doesn't combine a AlterModelOptions() with CreateModel() in the case below.
For example (using Django master):
testapp/models.py
from django.db import models class Credentials(models.Model): description = models.TextField() class Meta: db_table = 'credentials' # This was added after 0001_initial.py was generated: verbose_name_plural = 'credentials'
testapp/migrations/0001_initial.py
class Migration(migrations.Migration): initial = True dependencies = [ ] operations = [ migrations.CreateModel( name='Credentials', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('description', models.TextField()), ], options={ 'db_table': 'credentials', }, ), ]
testapp/migrations/0002_add_verbose_name_plural.py
class Migration(migrations.Migration): dependencies = [ ('testapp', '0001_initial'), ] operations = [ migrations.AlterModelOptions( name='credentials', options={'verbose_name_plural': 'credentials'}, ), ]
Expected squashed migration (via ./manage.py squashmigrations testapp 0002):
class Migration(migrations.Migration): replaces = [('testapp', '0001_initial'), ('testapp', '0002_add_verbose_name_plural')] initial = True dependencies = [ ] operations = [ migrations.CreateModel( name='Credentials', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('description', models.TextField()), ], options={ 'db_table': 'credentials', 'verbose_name_plural': 'credentials', }, ), ]
Actual squashed migration:
class Migration(migrations.Migration): replaces = [('testapp', '0001_initial'), ('testapp', '0002_add_verbose_name_plural')] initial = True dependencies = [ ] operations = [ migrations.CreateModel( name='Credentials', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('description', models.TextField()), ], options={ 'db_table': 'credentials', }, ), migrations.AlterModelOptions( name='credentials', options={'verbose_name_plural': 'credentials'}, ), ]
Attachments (1)
Change History (6)
comment:1 by , 9 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|---|
| Type: | Bug → Cleanup/optimization |
by , 9 years ago
| Attachment: | 0001-Refs-27717-Added-a-regression-test.patch added |
|---|
comment:2 by , 9 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
Thank you for the testcase - PR with that and fix opened :-)
comment:3 by , 9 years ago
| Has patch: | set |
|---|
comment:4 by , 9 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
Patch and tests look sensible to me.
Note:
See TracTickets
for help on using tickets.
Managed to reproduce with the provided patch.