Suppose I have this model which is associated with south:
class MyModel(models.Model):
field_a = models.CharField(max_length=30)
field_b = models.CharField(max_length=30)
Now later on I want to add one more field so I created that field between field_a and field_b now my model looks like:
class MyModel(models.Model):
field_a = models.CharField(max_length=30)
field_c = models.CharField(max_length=30)
field_b = models.CharField(max_length=30)
Then I migrated the changes, when checking the table structure in MySQL the field_c is created at the end of all fields. How can I tell south to maintain the fields order e.g. insert after field_a.
In MySQL we can insert the new field before or after any existing field. Is it possible to do that in south?
I do not believe that it is not possible to force the order of field creation in MySQL when using Django (or South). New fields will always be appended to the end of the table definition.
However: The order of the columns should be irrelevant to you. Read on…
If you’re writing SQL queries against your database, it is bad form to do
select *and rely on the field ordering of the table. Instead you should specify which fields you want to select, and the order in which you want them reported. This makes the underlying tables’ field-ordering unimportant.Additionally, if anyone in your organisation is currently writing reports which use
select *: by inserting new columns between others you could easily break reports that use field position (rather than field name), as the indexing of the columns will change.