I changed my model from
class HardwareModel(models.Model):
name = models.CharField(max_length=128,unique=True)
series =models.CharField(max_length=128)
def __unicode__(self):
return "%s" % (self.name)
to
class HardwareModel(models.Model):
name = models.CharField(max_length=128,unique=True)
series = models.ForeignKey(HardwareModelSeries, blank=True)
def __unicode__(self):
return "%s" % (self.name)
And I used south for migration. (with --auto so the migration script is made by south)
# Renaming column for 'HardwareModel.series' to match new field type.
db.rename_column('iamictinfra_hardwaremodel', 'series', 'series_id')
# Changing field 'HardwareModel.series'
db.alter_column('iamictinfra_hardwaremodel', 'series_id', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['iamictinfra.HardwareModelSeries']))
# Adding index on 'HardwareModel', fields ['series']
db.create_index('iamictinfra_hardwaremodel', ['series_id'])
Now while creating a totally new sqllite database (during testing), it gives this error:
south DEBUG execute "CREATE INDEX "iamictinfra_hardwaremodel_b18a98d" ON "iamictinfra_hardwaremodel" ("series_id");" with params "[]"
FATAL ERROR - The following SQL query failed: CREATE INDEX "iamictinfra_hardwaremodel_b18a98d" ON "iamictinfra_hardwaremodel" ("series_id");
The error was: index iamictinfra_hardwaremodel_b18a98d already exists
Now I can delete the create index command, but I Am not sure than it will work on production server (mySql).
Another option is probably to change the script and delete the column, and make it instead of altering it... However, I Am a lot of migrations further.... i thinks it's a bit tricky to mess in old migrations..... I tried to catch it with a try catch...
It might also be that this script was made using an older south version.... and in the newer the index is also renamed while altering a column... and in the old version it was not...
I Am using south 0.7.6 (the current latest).
any suggestions?
@Mariodev Sorry to dissapoint you, I did not find any solution for this.
As sqlite is not seen as a real database option for django by the south development community... it does not look like there is any solution in the near future. Maybe it's a bit more complicated that stated here, I think it has also something to do with running it on a development server (runserver) in staed of the real thing.
In my case the sqlite database was just my develop and test database (production ran on mySQL)
the problem does not occur in mySql
So my 'solution' was to delete the sqlite database (luckily i work with fixtures for population a new development database) and do a new syncdb and migrate.
Make sure you use fixtures, or backup the database with a dump command, so you can make a clean start...