class AAA(models.Model):
name = models.CharField()
class Meta:
db_table = 'aaa'
class BBB(models.Model):
name = models.CharField()
aaa = models.ForeignKey(AAA)
class CCC(models.Model):
name = models.CharField()
class Meta:
db_table = 'ccc'
class FooTwo(models.Model):
name = models.CharField()
ccc = models.ForeignKey(CCC)
(1). Models.py modified
class CCC(models.Model): <-Fixed AAA to CCC
name = models.CharField()
class Meta:
db_table = 'ccc' <-Modify aaa to ccc
class FooTwo(models.Model):
name = models.CharField()
aaa = models.ForeignKey(CCC) <- ForeignKey(AAA)Foreign Key(CCC)Fixed to
(2). Modify the migration file below after schemam migration
def forwards(self, orm):
db.rename_table('aaa', 'ccc')
def backwards(self, orm):
pass
(3). migrate --Check if the table name has changed AAA-> CCC
(4). Modify models.py
class CCC(models.Model):
name = models.CharField()
class Meta:
db_table = 'ccc'
class FooTwo(models.Model):
name = models.CharField()
ccc = models.ForeignKey(CCC) <-Modify aaa to ccc
(5). Modify the migration file below after schemam migration
def forwards(self, orm):
db.rename_column('ccc', 'aaa', 'ccc')
def backwards(self, orm):
pass
(6). migrate --Check if the column name has changed aaa-> ccc