Answer the question
In order to leave comments, you need to log in
Repeated initial migration from an existing db?
Previous story:
I somehow added a model to my app.
I migrated to the test server (but for some reason I didn’t check it)
Then I migrated to the main server, everything worked fine there.
Time passed, I had to return to this model on the test server.
I was surprised when I found that this model is not in the database.
My Action:
Without much thought, I decided that resetting the migrations would be a good way to go.
I deleted all the files from app-migrations
I deleted all the lines from the django_migrations database Run
makemigrations again
Then migrate, to which the answer was
:
migrate --fake app
I did (Applying app.0001_initial... FAKED)
, didn't work.
There were also tips to make syncdb, but this also doesn’t work at all.
migrate app 0001 is not the same either.
Before that, when the database was almost empty, I calmly deleted the migrations and cleaned the database, then did the migrations again and everything was fine.
Now I have a very large database volume, and it’s not very willing to do everything again (even just export and then import).
Question:
How to make an initial migration (0001_initial), for an already existing database, after deleting all migrations and doing makemigrations as if for the first time.
Answer the question
In order to leave comments, you need to log in
To roll back all migrations in the application, you need to do this:
Then apply them again:
If the migrations were changed, but not rolled back in advance, problems may arise: you will have to delete the table manually and apply all migrations to the application again. And if the initial file has changed, then on the two servers too.
And migrate --fake app_name is just an entry in django_migrations, no more
. And yes, you don’t need to recreate migrations every time - you’ll only make problems for yourself: there are some migrations, there are others, you rolled back there, you didn’t roll back there.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question