django-typed-models icon indicating copy to clipboard operation
django-typed-models copied to clipboard

Creation of instance in migration does not fill type field

Open pax0r opened this issue 5 years ago • 0 comments

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')

pax0r avatar Feb 13 '20 10:02 pax0r