"No installed app with label 'admin'" running Django migration. The app is installed correctly "No installed app with label 'admin'" running Django migration. The app is installed correctly python python

"No installed app with label 'admin'" running Django migration. The app is installed correctly


The Django doc makes it clear:

When writing a RunPython function that uses models from apps other than the one in which the migration is located, the migration’s dependencies attribute should include the latest migration of each app that is involved, otherwise you may get an error similar to: LookupError: No installed app with label 'myappname' when you try to retrieve the model in the RunPython function using apps.get_model().

Code example:

# Imports are omitted for the sake of brevitydef move_m1(apps, schema_editor):    LogEntry = apps.get('admin.logentry')    # Other business logic here ...class Migration(migrations.Migration):    dependencies = [        ('app1', '0001_initial'),        # Below is the manually added dependency, so as to retrieve models        # of 'django.contrib.admin' app with apps.get_model() in move_m1().        #        # Currently this is for Django 1.11. You need to look into        # 'django/contrib/admin/migrations' directory to find out which is        # the latest migration for other version of Django.        ('admin', '0002_logentry_remove_auto_add'),    ]    operations = [        migrations.RunPython(move_m1),    ]


Just check your setting.py in the installed apps section and make sure that you have added your app there :

# Application definition    INSTALLED_APPS = [        'django.contrib.admin',        'django.contrib.auth',        'django.contrib.contenttypes',        'django.contrib.sessions',        'django.contrib.messages',        'django.contrib.staticfiles',        '--- you need to add your app here ---',    ]


I don't know the exact cause for this. Will have to dig into the source code. but for now a workaround is add ('admin', 'name_of_last_migration_in_admin_app') to the dependencies and the migrations shall go alright.