Commit 872409b0 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis
Browse files

astakos: Fix sqlite-related issues in migration

In migration 0022, ProjectApplication's field `chain' is altered from
a plain integer field to a foreign key. This triggers a south command
to create an index for the said field. However, it seems that sqlite
creates this index automatically, before the create_index command is
issued, which subsequently fails. A check is added here, to handle
this case by skipping the create_index command.

Also, reinstate the data migration part, removed by commit 64c5e1e,
but only if db.dry_run is false. In sqlite, before actually applying
it, a migration is first dry run, in which case data-altering code
should not be run.
parent c0748844
......@@ -8,6 +8,11 @@ class Migration(SchemaMigration):
def forwards(self, orm):
if not db.dry_run:
objs = orm.ProjectApplication.objects
for (c,) in objs.values_list('chain').distinct():
# Changing field ''
db.alter_column('im_project', 'id','django.db.models.fields.related.OneToOneField')(unique=True, primary_key=True, db_column='id', to=orm['im.Chain']))
......@@ -17,8 +22,9 @@ class Migration(SchemaMigration):
# Changing field 'ProjectApplication.chain'
db.alter_column('im_projectapplication', 'chain','django.db.models.fields.related.ForeignKey')(db_column='chain', to=orm['im.Chain']))
# Adding index on 'ProjectApplication', fields ['chain']
db.create_index('im_projectapplication', ['chain'])
if db.backend_name != 'sqlite3':
# Adding index on 'ProjectApplication', fields ['chain']
db.create_index('im_projectapplication', ['chain'])
def backwards(self, orm):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment