Converting a model to multi-table inheritance in Django

Note: This article will be expanding Samuel Spencer’s article on http://www.kidstrythisathome.com/2016/10/wtf-django-moving-models-part1.html

In this case, I will handle two different models to be inherited from a base model.

Let’s say you had something like this already inside your app:

And later you realized that you don’t wanna use abstract model anymore but instead inherit them from a real base model. So your new structure will be like this:

After converting your structure to the final state, python manage.py makemigrations my_app won’t work, unfortunately. This issue is also mentioned in my reference article, and he also explains the issue with many to many relations therefore I won’t touch that issue. The problem in the reference article was that it assumed your id will be same as ptr_id but this happens only in the ideal condition.

Here is the migration code you should run to achieve your expectation:

I hope this helps.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.