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 3951026
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:40:50+00:00 2026-05-20T01:40:50+00:00

I have a Django model with a Person model: class Person(models.Model): # Personal details

  • 0

I have a Django model with a Person model:

class Person(models.Model):
  # Personal details
  first_name = models.CharField(max_length=50)
  middle_name = models.CharField(max_length=50, blank=True, null=True)
  last_name = models.CharField(max_length=50)
  gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
  date_of_birth = models.DateField()

  # Address
  street_address = models.CharField(max_length=50)
  suburb = models.CharField(max_length=30)
  postcode = models.CharField(max_length=4)
  state = models.CharField(max_length=3, choices=STATE_CHOICES)

  #Contact Details
  email = models.EmailField()

  # Family
  spouse = models.ForeignKey('self', null=True, blank=True)
  children = models.ManyToManyField('self', null=True, blank=True)

  home_church = models.ForeignKey('Church', null=True, blank=True)

The “middle_name” field is nullable, I don’t think there’s any way to avoid that, is there?

However, I also have a nullable ForeignKey for Spouse, a recursive ManyToManyField for their children, and a nullable ForeignKey for church (if relevant).

My question – firstly, what is the current consensus on nullable foreign keys? Should I be allowing it here, or should I be creating some kind of “nobody”, or “unassigned” model to represent not having a spouse/home church?

Or is there some other way that I can rework this design in Django to accommodate for this?

And if I do go ahead with null FK’s, are there any caveats in Django I need to be aware of? (left join?)

Cheers,
Victor

  • 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-20T01:40:51+00:00Added an answer on May 20, 2026 at 1:40 am

    Null is perfectly fine. In python code None will represent Null.

    One important thing you should know is that if you delete church, django performs cascading and your Persons from that church will be deleted too. So before deleting church you need to set Null on church field for every person in that church.

    Django 1.3 introduces on_delete argument which makes this a lot simper.

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

Sidebar

Related Questions

Say I have the following model: class Person(models.Model): street_address = models.CharField(max_length=50, blank=True) suburb =
Suppose I have a Django model as follows: class Person(models.Model): first_name = models.CharField(max_length=50) last_name
Say I have a Django class something like this: class Person(models.Model): name = models.CharField(max_length=50)
I have the following Django and Flex code: Django class Author(models.Model): name = models.CharField(max_length=30)
Given a class: from django.db import models class Person(models.Model): name = models.CharField(max_length=20) Is it
Consider the following models: class Person(models.Model): name = models.CharField(max_length=128) class Group(models.Model): name = models.CharField(max_length=128)
I have a Django model that looks something like this: class Person(models.Model): name =
(Django 1.x, Python 2.6.x) I have models to the tune of: class Animal(models.Model): pass
If I have a Django form such as: class ContactForm(forms.Form): subject = forms.CharField(max_length=100) message
I have a model like this: class Person(models.Model,Subject): name = .. The class Subject

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.