﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
22846	Migrations with custom fields fail	digitalle	nobody	"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\migrate.py"", line 139, in handle
    ProjectState.from_apps(apps),
  File ""C:\Python27\lib\site-packages\django-1.7b4-py2.7.egg\django\db\migrations\state.py"", 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\state.py"", line 164, in from_model
    e,
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."	Bug	closed	Migrations	dev	Release blocker	invalid			Unreviewed	0	0	0	0	0	0
