I have a model which has a nullable foreign key relation with itself (this 'self' can be any model which has this foreign key). This foreign key is a custom class which prevents cyclic relationships.
The call to super()
in the __init__
contains null=True
and blank=True
and therefor need to be included in the inspection rules of South. This makes at least the schemamigration work, but the migrate still fails.
Following code shows: the custom foreign key, the inspection rules and the model using the foreign key.
# Foreign key
class ParentField(models.ForeignKey)
def __init__(self, verbose_name=None, **kwargs):
super(ParentField, self).__init__('self', verbose_name=verbose_name, null=True, blank=True, **kwargs)
@staticmethod
def checkcyclic(object, attr):
'''Check for a cyclic relationship'''
pass
# Introspection rules
add_introspection_rules([
(
[ParentField],
[],
{
'null': ['null', {'default': True}],
'blank': ['blank', {'default': True}],
}
)
], ["^test\.models\.fields\.ParentField"])
# Model
class Relation(Model):
parent = ParentField(related_name='child_set')
Migrating gives the following error:
$ ./manage.py migrate
[..]
super(ParentField, self).__init__('self', verbose_name=verbose_name, null=True, blank=True, **kwargs)
TypeError: __init__() got multiple values for keyword argument 'to'
I've tried addding a rule like below, but that changed nothing.
'to': ['rel.to', {'default': 'test.models.Relation'}],
Can anyone tell me what I'm doing the wrong way or any hints to a solution for this?