#30467: `makemigrations app_label` sometimes tries to create migrations for
unrequested app_label
------------------------------------------------+------------------------
Reporter: Vsevolod Novikov | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Migrations | Version: 2.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
= The simplest scenario
== Prerequisites
{{{
#!bash
~/$ django-admin startproject mmbug
~/$ cd mmbug
~/mmbug$ python manage.py startapp app1
~/mmbug$ python manage.py startapp app2
}}}
Then modify `settings.py`:
{{{
#!python
...
INSTALLED_APPS = [
...
'app1',
'app2'
]
}}}
Then create models:
`app1/models.py`:
{{{
#!python
from django.db import models
# Create your models here.
class App1Model(models.Model):
field1 = models.CharField(max_length=10)
}}}
`app2/models.py`:
{{{
#!python
from django.db import models
# Create your models here.
class App2Model(models.Model):
field1 = models.CharField(max_length=10)
field2 = models.ForeignKey('app1.App1Model', on_delete=models.CASCADE)
}}}
Then create a migration for app1:
{{{
#!bash
~/mmbug$ python manage.py makemigrations app1
}}}
Then change app1 models file slightly and don't create migration for it:
`app1/models.py`:
{{{
#!python
from django.db import models
# Create your models here.
class App1Model(models.Model):
field1 = models.CharField(max_length=10, verbose_name='Field 1')
}}}
== What happens
The `makemigrations` command with applied `app_label` creates a migration
for two app_labels
{{{
#!bash
~/mmbug$ python manage.py makemigrations app2 --dry-run
Migrations for 'app1':
app1/migrations/0002_auto_20190509_0823.py
- Alter field field1 on app1model
Migrations for 'app2':
app2/migrations/0001_initial.py
- Create model App2Model
}}}
== What I expect
The `makemigrations` command with applied `app_label` should create a
migration for only noted app_label, probably with a warning, like
{{{
#!bash
~/mmbug$ python manage.py makemigrations app2 --dry-run
Migrations for 'app2':
app2/migrations/0001_initial.py
- Create model App2Model
WARNING: the app1 application has uncovered changes in models, it may
cause inconsistent migrations order
}}}
== When it interferes
Let we have installed a third-party module
- Case 1. Third-party package has model changes not covered by migration.
- Case 2. Third-party package has model fields dependent on settings
different in our project and installed package
If the module is installed in the `virtualenv`, the `makemigrations`
command will create a messy migration in the site-packages subfolder.
== Versions of Django
I reproduced this problem in Django 2.0, 2.1, and 2.2
--
Ticket URL: <https://code.djangoproject.com/ticket/30467>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/049.536b668b92bafda0de34744f4d2de7e0%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.