Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7585925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:17:46+00:00 2026-05-30T19:17:46+00:00

I have separate apps with a foreign key from a model in one model

  • 0

I have separate apps with a foreign key from a model in one model (the UserProfile model) to another app I’ve created. When I try to syncdb I’m getting that the foreign key id is NULL even though I have a fixture for it in that app. Is there a way to specify the order in which YAML files are loaded?

Here’s what the app structure looks like –

profile/

# models.py
class UserProfile(models.Model):
    user = models.OneToOneField(User)
    school = models.ForeignKey(School)


def create_user_profile(sender, instance, created, **kwargs):
    if created:
        UserProfile.objects.create(user=instance)

post_save.connect(create_user_profile, sender=User)

# fixtures/initial_data.yaml
-   fields:
        username: admin
        password: ***password hash here***
        date_joined: 2012-02-01 01:00:00
        email: email@email.com
        last_name: Last
        first_name: First
        groups: []
        is_active: true
        is_staff: true
        is_superuser: true
        last_login: 2012-02-01 01:01:00
        user_permissions: []
    model: auth.user
    pk: 1
-   fields:
        user: 1
        school: 1
    model: profile.UserProfile
    pk: 1

school/

# models.py
class School(models.Model):
    name = models.CharField(max_length=100)

# fixtures/initial_data.yaml
-   fields:
        name: "School"
    model: school.School
    pk: 1

And on syncdb I get:

IntegrityError: profile_userprofile.school_id may not be NULL

This must mean it’s saving the UserProfile model before the schools. So, I’m wondering if it’s at all possible to reorder the yaml files or somehow attribute the school to my UserProfile without allowing the school to be NULL.

In settings.py I’m loading school followed by profile in installed apps.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:17:47+00:00Added an answer on May 30, 2026 at 7:17 pm

    Right approach here is to use natural keys.

    If you can’t use it, you can load fixtures manually, just rename them and load by manage.py loaddata in the order you need.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two separate apps (one is classic asp, the other is asp.net) which,
I have two separate apps - one a client (in C#), one a server
I have two separate java maven projects: one is my web app itself and
I have several ASP.NET MVC 3 apps running on IIS 6 with separate app
We have two separate web-apps, say 'retailUI' and 'bulkUI'. These two are basically two
I have a main application, and a bunch of sub-applications (they are separate apps,
I have seen many apps that load data to UITableViews from the internet, and
I have resources in separate assemblies to be used by multiple WPF apps and
I have 2 web sites (in Visual Studio - separate solutions) - one in
I'm new to WCF. Let's say I have two asp.net apps, one that uses

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.