customcolumn

migrating django-model field-name change without losing data

回眸只為那壹抹淺笑 提交于 2019-11-29 23:54:58
I have a django project with a database table that already contains data. I'd like to change the field name without losing any of the data in that column. My original plan was to simply change the model field name in a way that would not actually alter the name of the db table (using the db_column column parameter): The original model: class Foo(models.Model): orig_name = models.CharField(max_length=50) The new model: class Foo(models.Model): name = models.CharField(max_length=50, db_column='orig_name') But, running South's schemamigration --auto produces a migration script that deletes the

migrating django-model field-name change without losing data

江枫思渺然 提交于 2019-11-28 19:49:10
问题 I have a django project with a database table that already contains data. I'd like to change the field name without losing any of the data in that column. My original plan was to simply change the model field name in a way that would not actually alter the name of the db table (using the db_column column parameter): The original model: class Foo(models.Model): orig_name = models.CharField(max_length=50) The new model: class Foo(models.Model): name = models.CharField(max_length=50, db_column=