Opened 5 years ago

Closed 5 years ago

#22846 closed Bug (invalid)

Migrations with custom fields fail

Reported by: digitalle Owned by: nobody
Component: Migrations Version: master
Severity: Release blocker Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I have some custom fields like:

class ProtectedForeignKey(models.ForeignKey):
    def __init__(self, *args, **kwargs):
        super(ProtectedForeignKey, self).__init__(*args, on_delete=models.PROTECT, **kwargs)

1.6 version worked fine.

1.7 validates and runs server also without problems.

But when I try to run syncdb for the first time I get error:

File "C:\Python27\lib\site-packages\django-1.7b4-py2.7.egg\django\core\management\commands\", line 139, in handle
  File "C:\Python27\lib\site-packages\django-1.7b4-py2.7.egg\django\db\migrations\", line 97, in from_apps
    model_state = ModelState.from_model(model)
  File "C:\Python27\lib\site-packages\django-1.7b4-py2.7.egg\django\db\migrations\", line 164, in from_model
TypeError: Couldn't reconstruct field company on company.ListAddress: __init__() got multiple values for keyword argument 'on_delete'

This fix solved the problem:

class ProtectedForeignKey(models.ForeignKey):
    def __init__(self, *args, **kwargs):
        kwargs.setdefault('on_delete', models.PROTECT)
        super(ProtectedForeignKey, self).__init__(*args, **kwargs)

but I have another couple of custom fields which set default kwargs like "validators"
and syncdb fails on that fields with the same error but different key argument.

Change History (2)

comment:1 Changed 5 years ago by digitalle

Version: 1.7-beta-2master

comment:2 Changed 5 years ago by Andrew Godwin

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top