Example of auto generated migration with unused import:
{{{
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('city', '0003_auto_20150305_0928'),
]
operations = [
migrations.AlterModelOptions(
name='city',
options={'verbose_name': 'City', 'verbose_name_plural':
'Cities'},
),
]
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24514>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/24514#comment:1>
* owner: nobody => chrisjluc
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/24514#comment:2>
Comment (by MarkusH):
I think `models` is a convenience import and should stay around.
--
Ticket URL: <https://code.djangoproject.com/ticket/24514#comment:3>
Comment (by chrisjluc):
I think having `models` in a migration that doesn't use the import might
spark confusion for why it's being imported in the first place. I think it
makes the migrations cleaner by not having unused imports. I don't see
many situations where someone would manually need the `models` import.
But, in the rare occasion that they do need it, manually adding it is not
that bad. @MarkusH
--
Ticket URL: <https://code.djangoproject.com/ticket/24514#comment:4>
Comment (by hugotacito):
Personally I'm having problems when I do automated code analysis with
pylint. I know this can be solved just ignoring the migrations folder but
it would be nice if django only do this import when necessary on auto
generated migrations.
--
Ticket URL: <https://code.djangoproject.com/ticket/24514#comment:5>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/24514#comment:6>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"a7bc00e17bebe34cdf23f744937b3c386ee73d81" a7bc00e1]:
{{{
#!CommitTicketReference repository=""
revision="a7bc00e17bebe34cdf23f744937b3c386ee73d81"
Fixed #24514 -- Made migration writer omit models import if it's unused.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24514#comment:7>