[Solved]-Where is the Django migrations folder?

10👍

Short answer: the migrations originate from Django apps and third party apps you installed in INSTALLED_APPS. Not the ones you defined yourself.

Migrations are generated per app, and are stored in some_app/migrations.

Even if you do not define migrations for your apps, there will usually be migrations that take place, since you (likely) included some apps defined by Django (and other third parties) in your INSTALLED_APPS, these have migrations as well.

For example most likely your INSTALLED_APPS contains:

# settings.py

INSTALLED_APPS = [
    # ...
    'django.contrib.auth',
    # ...
]

If we take a look at the source code of this app [GitHub], we see the migrations directiory. By adding this app to the INSTALLED_APPS you thus have added apps defined in the Django library itself (or by third parties) to your project, and the migrations of these apps are thus processed in the same way (in fact there is nothing "magical" about these apps, it is more that these handle common problems such that you do not need to care about these anymore).

The django.contrib.auth app has a file structure like (ommitting noise):

django/
    contrib/
        auth/
             migrations/
                __init__.py
                0001_initial.py
                0002_alter_permission_name_max_length.py
                0003_alter_user_email_max_length.py
                0004_alter_user_username_opts.py
                0005_alter_user_last_login_null.py
                0006_require_contenttypes_0002.py
                0007_alter_validators_add_error_messages.py
                0008_alter_user_username_max_length.py
                0009_alter_user_last_name_max_length.py

These are extactly the same migrations you see on the console when you perform migrations for the auth app (second section).

4👍

Django Project is actually a combination of a few Applications and Configuration files.

Applications and Configuration are actually Python Modules/Packages. Every project has a few default apps installed and they are mentioned in INSTALLED_APPS (see project settings.py).

These are the default apps and they are not stored/installed in your project: they reside inside Django package by default.

Example:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

For example, django.contrib.admin app is used with your application: the migrations directory for this app is available at site-packages/django/contrib/admin/migrations, but migrations from apps that you created, are all stored inside each app folder.

👤Sopan

Leave a comment