mike rodent
mike rodent

Reputation: 15652

Where is the Django database containing the django_migrations table?

This question asks where the Django installation is.

This question is about the table django_migrations.

I've looked under the path from the command django in the interactive console, where I find a subdirectory db, along with middleware, etc.

But I've no idea where this table django_migrations (i.e. the data in it) is in fact kept.

I want to know firstly because I want to know what happens if this data is lost. I'm just learning Django and I don't quite understand how much of a problem this would be.

The path to the Django location is under a directory in my home folder where I keep my Python virtual environments, the name of which begins with a ".". I tend to exclude such directories from my backup plans...

Having just deleted db.sqlite3 in my project I see that it gets regenerated when you do migrate, together with a list of (in my present case) some 15 migration operations. I'm quite mystified by some of these: the first 10 or so seem to have occurred before I started doing anything to my models.py file. Are they documented or explained somewhere?

Upvotes: 0

Views: 1958

Answers (2)

deceze
deceze

Reputation: 522175

All tables exist in the database that you configure in settings.py; by default that's an SQLite database in your project directory.

When running the migrate command, Django gathers all migrations from all apps you have installed (INSTALLED_APPS in settings.py). By default that includes things like django.contrib.auth, which defines a bunch of migrations related to user accounts. It's what gives you the out-of-the-box user management features of Django.

Upvotes: 1

Azamat Galimzhanov
Azamat Galimzhanov

Reputation: 638

If you use default django setup with sqlite there's a file db.sqlite3 - this is your database.

When you say it's being "regenerated" - it's being built by migrations. When you run python manage.py migrate you can see a bunch of migrations from installed django apps, including some default ones, like django.contrib.auth containing User model.

Migrations are stored within the <app_name>/migrations directory. You can check out some default migrations here, that's default auth migrations, but there are more.

Upvotes: 0

Related Questions