Q:

IntegrityError when loading Django fixtures with OneToOneField using SQLite

When attempting to load initial data via the syncdb command, Django throws the following error:
django.db.utils.IntegrityError: Problem installing fixtures: The row in table     'user_profile_userprofile' with primary key '1' has an invalid foreign key: user_profile_userprofile.user_id contains a value '1' that does not have a corresponding value in user_customuser.id.

There is a OneToOne relationship between the UserProfile model and CustomUser:
class UserProfile(TimeStampedModel):
    user = models.OneToOneField(settings.AUTH_USER_MODEL, null=True, blank=True)

Running ./manage.py dumpdata user --format=json --indent=4 --natural-foreign produces the following:
CustomUser Model Data
[
{
    "fields": {
        "first_name": "Test",
        "last_name": "Test",
        "is_active": true,
        "is_superuser": true,
        "is_staff": true,
        "last_login": "2014-10-21T11:33:42Z",
        "groups": [],
        "user_permissions": [],
        "password": "pbkdf2_sha256$12000$Wqd4ekGdmySy$Vzd/tIFIoSABP9J0GyDRwCgVh5+Zafn9lOiTGin9/+8=",
        "email": "test@test.com",
        "date_joined": "2014-10-21T11:22:58Z"
    },
    "model": "user.customuser",
    "pk": 1
}
]

Running ./manage.py dumpdata user_profile --format=json --indent=4 --natural-foreign produces the following:
Profile Model
[
{
    "fields": {
        "weight": 75.0,
        "created": "2014-10-21T11:23:35.536Z",
        "modified": "2014-10-21T11:23:35.560Z",
        "height": 175,
        "user": 1,
    },
    "model": "user_profile.userprofile",
    "pk": 1
}
]

Loading just the CustomUser model's initial data and then following up with UserProfile via load data works great, which suggests to me syncdb is attempting to load UserProfile before CustomUser has been loaded.
If the simplest solution would be to force the load order, what would the simplest way be to do this?

A:

I guess you should use Migrations https://docs.djangoproject.com/en/1.7/topics/migrations/ , they are ordered. But if you using older Django version then 1.7, install south https://south.readthedocs.org/en/latest/

