django-polymorphic
django-polymorphic copied to clipboard
remove poly base model
hey all wish have a good day. i have some models like this:
class BaseModel(PolymorphicModel):
review_average = models.FloatField(default=0.0, verbose_name=_('Review Average'))
tags = tagulous.models.TagField(to=Tag, blank=True)
sort = models.IntegerField(default=0, verbose_name=_('Sort'))
class Teacher(BaseModel):
user_obj = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name=_('User'))
slider_segment_obj = models.ForeignKey(SliderSegment, null=True, blank=True, on_delete=models.CASCADE, verbose_name=_('Slider Semgent'))
biography = models.TextField(null=False, blank=False, verbose_name=_('Biography'))
now i want to delete poly base model and transfer records from base model to teachers table. i cant create new class like NewTeacher because i used many times teacher model in project. any documentation to do this ?
Add the fields review_average_temp, tags_temp, and sort_temp to Teacher as nullable fields and makemigrations. Make a data migration that copies all data from BaseModel to the temporary rows in Teacher. Remove the base model from Teacher instead inheriting from models.Model and makemigrations. Rename the fields you added to remove temp and makemigrations.
Make sure you check the generated migrations each time to see that it's picking up the right renames and not creating blank new stuff and deleting the old stuff.
This is a Django thing, rather than a polymorphic thing, which is why you may be having difficulty finding documentation. The search term that will help you find more help is "django data migrations".