so I've already created models in Django for my db, but now want to rename the model. I've change the names in the Meta class and then make migrations/migrate but that just creates brand new tables.
I've also tried schemamigration but also not working, I'm using Django 1.7
Here's 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
Cheers
Create or update a model. Run ./manage.py makemigrations <app_name> Run ./manage.py migrate to migrate everything or ./manage.py migrate <app_name> to migrate an individual app. Repeat as necessary.
Model Meta is basically the inner class of your model class. Model Meta is basically used to change the behavior of your model fields like changing order options,verbose_name, and a lot of other options. It's completely optional to add a Meta class to your model.
Django does not know, what you are trying to do. By default it will delete old table and create new. You need to create an empty migration, then use this operation (you need to write it by yourself):
https://docs.djangoproject.com/en/stable/ref/migration-operations/#renamemodel
Something like this:
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('yourappname', '0001_initial'),
]
operations = [
migrations.RenameModel("OldName", "NewName")
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With