Opened 11 years ago
Closed 11 years ago
#22846 closed Bug (invalid)
Migrations with custom fields fail
| Reported by: | digitalle | Owned by: | nobody |
|---|---|---|---|
| Component: | Migrations | Version: | dev |
| 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 |
Description
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.
Change History (2)
comment:1 by , 11 years ago
| Version: | 1.7-beta-2 → master |
|---|
comment:2 by , 11 years ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Please read https://docs.djangoproject.com/en/dev/releases/1.7/#new-method-on-field-subclasses - custom fields need changing for 1.7.