Python Migrate issue
I encountered an error whilst building an application in Python this morning, I had the feeling that it would be a naming issue and a Stackoverflow post confirmed this.
The problem arose when attempting to build a model migration file using makemigrations
python manage.py makemigrations
Which returned the following error:
django.core.exceptions.ImproperlyConfigured: Cannot import 'apps.accounts'. Check that 'mysite.apps.accounts.apps.AccountsConfig.name' is correct.
The solution? The name in apps.py should be the same value that you put in INSTALLED_APPS in settings.py:
apps.py
from django.apps import AppConfig
class AccountsConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "mysite.apps.accounts"
settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'mysite.apps.accounts',
]