Ticket #444 (closed defect: wontfix)

Opened 6 years ago

Last modified 5 years ago

South reports error: when creating mysql CharField with max_length > 1000.

Reported by: fcamel@… Owned by: andrew
Priority: major Milestone: 0.7.1
Component: commands Version: 0.7
Keywords: Cc:


Server info:

  • Ubuntu 8.04
  • MySql 5.0.51a (allow varchar with at most 65536 bytes)


class Post(models.Model):
    content = models.CharField(max_length=1024, db_index=True)

"./manage.py schemamigration myapp init --initial" generates:

    def forwards(self, orm):

        # Adding model 'Post'
        db.create_table('myapp_post', (
            ('content', self.gf('django.db.models.fields.CharField')(max_length=1024, db_index=True)),
            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
        db.send_create_signal('myapp', ['Post'])

But South reports error when running "migrate":

_mysql_exceptions.Warning: Specified key was too long; max key length is 1000 bytes

mysql table seems OK and the index is made.
This also happens when use South to add index.

Change History

comment:1 Changed 6 years ago by fcamel@…

I found that adding an index with key length (<1000 bytes) works. So currently I execute raw sql in the migration script. Is it possible to assign such info in South? Or let South detect that max_length is exceed the limit and then add such info automatically?

Btw, depending on the character set, the max key length varies. For example, the following sql causes the same error if I use unicode as the charset:
ALTER TABLE my_table ADD INDEX my_index_nam ( my_column)

But this works:
ALTER TABLE my_table ADD INDEX my_index_nam ( my_column (300))

comment:2 Changed 6 years ago by andrew

  • Status changed from new to closed
  • Resolution set to wontfix
  • Milestone set to 0.7.1

This is a very similar problem to #293, but with indices. I'm not sure what South can do here - we don't know how to cut up the lengths of every field so it'll fit inside the limit, so unless someone can come up with a good way to always keep the indices under 1000 bytes, I'll have to WONTFIX.

comment:3 follow-up: ↓ 4 Changed 5 years ago by dana.spiegel@…

How about at least letting an index name be specified in the migration?

comment:4 in reply to: ↑ 3 Changed 5 years ago by andrew

Replying to dana.spiegel@…:

How about at least letting an index name be specified in the migration?

We can't - the SQL that makes the index is created by the Django core code, and as far as I know there's no option in there to set a custom index name yet.

Note: See TracTickets for help on using tickets.