I changed a SlugField to CharField. The database level did not change, since both fields create the
same schema.
{{{
# models.py
class EmailSender(models.Model):
- id=models.SlugField(primary_key=True)
+ id=models.CharField(primary_key=True, max_length=50, validators=[RegexValidator(r'^[a-zA-Z0-9_.-]+$')])
}}}
The migration created with --auto looks like this:
{{{ migration
class Migration(SchemaMigration):
def forwards(self, orm):
# Changing field 'EmailSender.id'
db.alter_column('modwork_emailsender', 'id', self.gf('django.db.models.fields.CharField')(max_length=50,
primary_key=True))
# Removing index on 'EmailSender', fields ['id']
db.delete_index('modwork_emailsender', ['id'])
}}}
{{{ psql \d modwork_emailsender
modwork_tbz_d=> \d modwork_emailsender
Table "public.modwork_emailsender"
Column | Type | Modifiers
--------+-----------------------+-----------
id | character varying(50) | not null
email | character varying(75) | not null
footer | text |
Indexes:
"modwork_emailsender_pkey" PRIMARY KEY, btree (id)
"modwork_emailsender_email_uniq" UNIQUE, btree (email)
}}}
2012-01-13 10:04:36 generic: DEBUG south execute "DROP INDEX "modwork_emailsender_id"" with params "[]"
django.db.utils.DatabaseError: ERROR: Index »modwork_emailsender_id« does not exist
I removed the "delete_index()" and the migration was successfull. I run the migration, because I wanted to
know if all goes well. I could have deleted all code in forward(), because nothing at database level changed.
Should I create a ticket?
Thomas
--
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de
> I removed the "delete_index()" and the migration was successfull. I run
> the migration, because I wanted to
> know if all goes well. I could have deleted all code in forward(),
> because nothing at database level changed.
>
> Should I create a ticket?
The fields are actually different - SlugField has db_index=True by
default, which is why South tried to delete the index - I'm not sure why
it failed, you should have one.
Andrew
the field is (and was before the migration) a primary key. Maybe this was the problem. Does south create an index for this:
SlugField(primary_key=True)
Ah, of course, the primary key still has an explicit index. It's a bug,
then, so feel free to file it, though I can't promise a timely fix at
the moment.
Andrew