Django DoesNotExist Accessing Attribute
May 14, 2010
I have a django model generated from a database. I was getting a really strange problem on one of the fields. This line of code:
self.linked_xml_class = pAttribute.linked_xml_class
failed with a DoesNotExist
exception. Yet, if I dir(pAttribute) it does have that attribute on.
The problem occurred because the database column was specified to be nullable, and in this case contained null. The attribute was defined like this:
linked_xml_class = models.ForeignKey(XmlClass, db_column='xab_linked_xml_class')
when it should have been:
linked_xml_class = models.ForeignKey(XmlClass, db_column='xab_linked_xml_class', blank=True, null=True)