SlugField to CharField (Primarykey)

31 views
Skip to first unread message

Thomas Guettler

unread,
Jan 13, 2012, 4:15:39 AM1/13/12
to South Users
Hi,

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

Andrew Godwin

unread,
Jan 13, 2012, 5:52:53 AM1/13/12
to south...@googlegroups.com
On 13/01/12 09:15, Thomas Guettler wrote:
> Hi,
>
> I changed a SlugField to CharField. The database level did not change,
> since both fields create the
> same schema.

> 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


Thomas Guettler

unread,
Jan 13, 2012, 6:13:25 AM1/13/12
to south...@googlegroups.com

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)

Andrew Godwin

unread,
Jan 13, 2012, 6:14:46 AM1/13/12
to south...@googlegroups.com
On 13/01/12 11:13, Thomas Guettler wrote:
>
>
> On 13.01.2012 11:52, Andrew Godwin wrote:
>> On 13/01/12 09:15, Thomas Guettler wrote:
>>> Hi,
>>>
>>> I changed a SlugField to CharField. The database level did not change,
>>> since both fields create the
>>> same schema.
>>
>>> 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.
>
> 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

Reply all
Reply to author
Forward
0 new messages