I've been a user of Django for about 2 years now and there is a feature I have always been afraid of using : faking migrations.
I've looked pretty much everywhere and the most information I can get is from the documentation where it states that:
--fake
Tells Django to mark the migrations as having been applied or unapplied, but without actually running the SQL to change your database schema.
This is intended for advanced users to manipulate the current migration state directly if they’re manually applying changes; be warned that using --fake runs the risk of putting the migration state table into a state where manual recovery will be needed to make migrations run correctly.
--fake-initial
Allows Django to skip an app’s initial migration if all database tables with the names of all models created by all CreateModel operations in that migration already exist. This option is intended for use when first running migrations against a database that preexisted the use of migrations. This option does not, however, check for matching database schema beyond matching table names and so is only safe to use if you are confident that your existing schema matches what is recorded in your initial migration.
I get the general idea and why one would want to use this feature. But, I don't understand the part where it says that this is intended for advanced users only.
Can someone explain what is happening behind the scene and why manual recovery would be needed.
NOTE
I'm not looking for the exact raw SQL queries that runs when faking a migration. I'm only looking for a general idea of what is happening behind the scene and maybe an example of why faking a migration
would result in a state where makemigrations
would not be working correctly.
--fake
, marking migrations as applied or not, is defined atdjango_migrations
table, where Django keeps track of all applied migrations for an app, with thename
of the migration file and when it was applied. It took me a while to figure this, since that the documentation isn't clear about this detail which I presented here. – Shebashebang