I\'m planning to rename several models in an existing Django project where there are many other models that have foreign key relationships to the models I would like to rena
Unfortunately, I found problems (each django 1.x) with rename migration which leave old table names in the database.
Django doesn't even try anything on the old table, just rename his own model. The same problem with foreign keys, and indices in general - changes there are not tracked properly by Django.
The simplest solution (workaround):
class Foo(models.Model):
name = models.CharField(unique=True, max_length=32)
...
Bar = Foo # and use Bar only
The real solution (an easy way to switch all indices, constraints, triggers, names, etc in 2 commits, but rather for smaller tables):
commit A:
# deprecated - TODO: TO BE REMOVED
class Foo(model.Model):
...
class Bar(model.Model):
...
Bar only.
(including all relations on the schema)In migration prepare RunPython, which copy data from Foo to Bar
(including id of Foo)
commit B: (no rush, do it when an entire team is migrated)
Foofurther cleanup:
bug in Django: