How can I undo this (accidental) table inheritance in Django?

15 Views Asked by At

I've got a django app library in production, and have found a major flaw.

The library declares AbstractMyModel from which a concrete MyModel inherits. Users of the library can choose to install the app and use MyModel directly, or just import the abstract models to do their own thing with.

The problem is that AbstractMyModel isn't abstract. I forgot to include a class Meta() declaring abstract=True.

So I basically have a table inheritance in production:


class AbstractMyModel(models.Model):
    """Abstract model... EXCEPT IT'S NOT!!!"""

    name = models.SlugField(
        help_text="name",
        unique=True,
    )


class MyModel(AbstractMyModel):
    """ARGH - the abstract one isn't actually abstract
    But I've got this in production - there are two actual tables from
    AbstractMyModel and MyModel. How can I sort this mess out?"""

QUESTION: How would I migrate my way out of this, to collapse the inheritance and end up with the MyModel table as concrete and AbstractMyModel as truly abstract?

TIA!

EDIT

Question found to be a duplicate of Migrate from multi-table inheritance model to abstract base classes in Django

I've voted to close.

0

There are 0 best solutions below