I want to have initial data for tables like Users and Options.
For old django the fixtures was very easy way to do but now django says to do it in migration way which i don't fully understood.
Now i already have 10 migrations in my migrations folder. I am confused where do i keep my initial data migration file .
If i make it like 0011_initial_data and put it in other migration then it will get lost in long list of migration and its not easy noticeable to new user to see what is that . and also if someone squash the migration then no one will know if there is some data in there.
I want to keep it separate in some folder called data migration . How can i do that
This is the example code from their site. But where do i place it so that it don't get mixed up
# -*- coding: utf-8 -*-
from django.db import models, migrations
def combine_names(apps, schema_editor):
# We can't import the Person model directly as it may be a newer
# version than this migration expects. We use the historical version.
Person = apps.get_model("yourappname", "Person")
for person in Person.objects.all():
person.name = "%s %s" % (person.first_name, person.last_name)
person.save()
class Migration(migrations.Migration):
dependencies = [
('yourappname', '0001_initial'),
]
operations = [
migrations.RunPython(combine_names),
]