django-dynamic-fixture foreign key to self -
i have tests.py looks this:
from django_dynamic_fixture import g,n person.models import person django.test import testcase class emailsendtests(testcase): def test_send_email(self): person = n(person)
my person model looks this:
class person(models.model): person_no = models.integerfield(primary_key=true) address = models.foreignkey('address', db_column = 'address_no') guarantor = models.foreignkey('person', db_column = 'gperson_no')
when run tests, following:
valueerror: cannot assign none: "patient.guarantor" not allow null values.
how create django_dynamic_fixture object has foreignkey pointing itself?
from understand n function doesn't assign id, since it's not generated in db, maybe reason:
https://github.com/paulocheque/django-dynamic-fixture/wiki/documentation#wiki-n
other thing, instead
guarantor = models.foreignkey('person', db_column = 'gperson_no')
you should
guarantor = models.foreignkey('self', db_column = 'gperson_no')
https://docs.djangoproject.com/en/dev/ref/models/fields/#foreignkey
hopefully solve issue..
edit
i figured out, need provide null=true self referenced field, make work, makes sense, since self reference must end somewhere.
Comments
Post a Comment