Renaming models (tables) in Django

so I already created models in Django for my db, but now I want to rename the model. I changed the names in the Meta class and then performed the migration / migration, but this only creates new tables.

I also tried schematization, but also did not work, I use Django 1.7

Here is my model

class ResultType(models.Model): name = models.CharField(max_length=150) ut = models.DateTimeField(default=datetime.now) class Meta: db_table = u'result_type' def __unicode__(self): return self.name 

Greetings

+7
python django migrate renaming makemigrations
source share
1 answer

Django does not know what you are trying to do. By default, it will delete the old table and create a new one. You need to create an empty migration, and then use this operation (you need to write it yourself):

https://docs.djangoproject.com/en/stable/ref/migration-operations/#renamemodel

Something like that:

 class Migration(migrations.Migration): dependencies = [ ('yourappname', '0001_initial'), ] operations = [ migrations.RenameModel("OldName", "NewName") ] 
+17
source share

All Articles