Reputation: 6213
I have an existing database filled with a bunch of data. I want to migrate to Django so I went ahead and created the necessary models with python manage.py inspectdb
. I haven't changed anything besides removed the managed = False
since I want Django to manage the tables (mistake perhaps for initial migration?).
So now that the models are ready, how can I generate the first migration file so that I can start changing the fields to generate additional migrations (renaming a field here and there). I understand python manage.py migrate
will handle the creation of Django-specific models but does not actually create any migration files? Some sources indicate the first migration file should be run with --fake
so it's not applied. Will the next migration files remember to run the first one as fake and only apply the next ones?
Upvotes: 3
Views: 1511
Reputation: 308879
You want makemigrations
to create the migrations. The migrate
command applies migrations, it does not create them.
You can use the --fake-initial
option so that Django does not try to create the tables that already exist. Note that --fake
and --fake-initial
are two different commands.
When you run migrate
, the django_migrations
table is updated to store the currently applied migrations. The migration files themselves are not changed. The --fake
command updates the django_migrations
table without running the migration. That means that if you use it incorrectly your database and django_migrations
table can get out of sync, which can be difficult to fix.
Upvotes: 3