I have a table FilmWork which is linked to a table Perosn via FilmWorkPerson table. I am trying to populate them with fake data
I have basically used this example:
https://factoryboy.readthedocs.io/en/rbarrois-guide/recipes.html#many-to-many-relation-with-a-through
factories.py:
class PersonTestFactory(DjangoModelFactory):
class Meta:
model = Person
id = factory.Faker('uuid4')
name = factory.Faker("sentence", nb_words=1)
class FilmWorkTestFactory(DjangoModelFactory):
class Meta:
model = FilmWork
id = factory.Faker('uuid4')
title = factory.Faker("company")
class FilmWorkPersoTestFactory(factory.django.DjangoModelFactory):
class Meta:
model = FilmWorkPerson
movie_id = factory.SubFactory(FilmWorkTestFactory)
person_id = factory.SubFactory(PersonTestFactory)
class FilmWorkPersoTestFactory2(FilmWorkTestFactory):
membership = factory.RelatedFactory(
FilmWorkPersoTestFactory,
factory_related_name='movie_id',
)
But when I call FilmWorkPersoTestFactory2()
, it returns an error: ['“Fisher, Smith and Ford” is not a valid UUID.']
. I think it takes title instead of id and I do not understand how to point it to the correct field.
question from:
https://stackoverflow.com/questions/65891878/factoryboy-returns-wrong-field-when-using-subfactory 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…