craigds/django-typed-models

Creation of instance in migration does not fill type field

Opened this issue · 0 comments

pax0r commented

Let's say we will have code like that in migration:

ChildModel = apps.get_model('app', 'ChildModel')
ChildModel.objects.create(field='a')

The instance of parent model is saved in DB with type field set as empty string.

While there is probably nothing we can do about it (as apps.get_model just looks at the table specification on given point in time) I think it's worth mention somewhere about this limitation as this might lead to hard to debug errors.

The workaround is to always set type in migration, i.e.:

ChildModel = apps.get_model('app', 'ChildModel')
ChildModel.objects.create(field='a', type='app.childmodel')