Reputation: 2518
I can run manage.py flush
to purge the database. Now, how do I reload the initial data from the migrations file?
If I run manage.py migrate unit
I get the following:
Operations to perform:
Apply all migrations: unit
Running migrations:
No migrations to apply.
My migration file mostly follows the example from the docs, except I modified the 0001 file to run the data loads after schema creation. E.g.,
class Migration(migrations.Migration):
dependencies = []
operations = [
# django makemigration generated schema stuff
...
# data creation stuff...
migrations.RunPython(models_1_create, models_1_reverse),
migrations.RunPython(models_2_create, models_2_reverse),
]
Upvotes: 0
Views: 381
Reputation: 43300
You can't, migrations are for modifying a databases schema, with data migrations to modify existing data.
You're better off making that a custom management command,
or if you really insist on redoing the migration, since you've already flushed the database, why not just drop the database completely and recreate it, then you'll be able to migrate again.
See also providing initial data with fixtures
Upvotes: 1