﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
30467	`makemigrations app_label` sometimes tries to create migrations for unrequested app_label	Vsevolod Novikov	nobody	"= 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
"	Cleanup/optimization	closed	Migrations	2.2	Normal	invalid			Unreviewed	0	0	0	0	0	0
