python - How do I populate the Django table MyApp_user_groups in a yaml fixture? -


my question similar how populate django table django_site in yaml fixture? , need on this.

i create group in auth_group table in yaml fixture:

- model: auth.group   pk: 1     fields:     name: admin 

in mysql have django table named: myapp_user_groups, myapp name of django app; table automatically created django. table should connect myapp.user model (created me) groups model of django. using yaml fixture, want add tuple in table (for purpose of add user group automatically when run syncdb), receive following error:

deserializationerror: invalid model identifier: myapp.user_groups 

so code is

- model: myapp.user_groups   pk: 1     fields:     user_id: 2     group_id: 1 

i'm newbie django. ideas?

if use django >= 1.7 (with migrations) (and should) use data migrations. https://docs.djangoproject.com/en/1.7/topics/migrations/#data-migrations

def create_group(apps, schema_editor):     group = apps.get_model("auth", "group")     g = group.objects.create("your group name")     usergroup = apps.get_model("myapp", "user_group")     usergroup.objects.create(user_id=2, group_id=g.id)   class migration(migrations.migration):      dependencies = [         ('myapp', '0001_initial'),         ('auth','0001_initial'),     ]      operations = [         migrations.runpython(create_group),     ] 

Comments