Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creation of instance in migration does not fill type field #54

Open
pax0r opened this issue Feb 13, 2020 · 0 comments
Open

Creation of instance in migration does not fill type field #54

pax0r opened this issue Feb 13, 2020 · 0 comments

Comments

@pax0r
Copy link

pax0r commented Feb 13, 2020

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')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant