Using Faker to fill multiple tables with FKs

I am trying to populate my Django project with some test data using Faker. I have 3 tables, Person, Address, Employment. Both Address and Employment have a Person FK. My script is creating my person but when it gets to Address it fails at Address.person


class Person(models.Model):
    first_name = models.CharField(max_length=200)
    middle_name = models.CharField(max_length=200)
    last_name = models.CharField(max_length=200)

class Address(models.Model):
    person = models.ForeignKey(Person, on_delete=models.CASCADE)
    address = models.CharField(max_length=200, blank=True, null=True)

class Employment(models.Model):
    person = models.ForeignKey(Person, on_delete=models.CASCADE)
    employer = models.CharField(max_length=200)

My script

def populate(n=5):
    for entry in range(n):
        person = Person.objects.get_or_create(
            first_name = fakegen.first_name(),
            middle_name = fakegen.first_name(),
            last_name = fakegen.last_name(),


def FakeAddress(person):
    address = Address.objects.get_or_create(
        person = person,
        address = fakegen.street_address(),
TypeError: Field 'id' expected a number but got <Person: Michael Baker>.

I’ve tried to pass the Person to the address function and I get TypeError: Field 'id' expected a number but got <Person: Michael Baker>. Next I tried passing the Person’s ID instead of the person and I get ValueError: Cannot assign "93": "Address.person" must be a "Person" instance.

get_or_create returns a tuple - you want only the first element - QuerySet API reference | Django documentation | Django


person, _created = Person.objects.get_or_create(...)
Address.objects.get_or_create(person=person, ...)