OnetoOneField and ForeignKey with unique=True both fail
Closed this issue · 2 comments
CreateInstanceError: Cannot solve constraints for "supporters.Person", tried 1000 times. Please check value generators or model constraints. At least the following fields are involved: user
the model:
class Person(models.Model):
user = models.ForeignKey(User, unique=True)
or
class Person(models.Model):
user = models.OneToOneField(User)
Seems like this should be easy to handle...not sure why it is having this failure.
This error occurs when you don't have enough User
instances around to fill in the needed relations. Either create more User
objects beforehand or try passing generate_fk=True
to the Autofixture
class like this:
fixture = AutoFixture(Person, generate_fk=True)
fixture.create()
Or on the command line:
python manage.py loadtestdata supporters.Person:10 --generate-fk
If you don't find the solution with the help explained above, feel free to reopen the ticket.
My apologies - I forgot to include the fact that I am setting generate_fk=True
on the AutoFixture instance! Hence my surprise...
I don't think I have the necessary permissions to reopen the ticket myself.