Django says that MySQL does not allow unique CharFields to have a max_length > 255, but it does

Viewed 3620

I've got an existing mysql database with the following table:

CREATE TABLE IF NOT EXISTS NetworkServerGroups (
        GroupID INTEGER UNSIGNED PRIMARY KEY AUTO_INCREMENT,
        GroupName VARCHAR(2048) UNIQUE NOT NULL
        )

After running Django's inspectdb tool, it's generated the following model (I manually modified the class name to remove the trailing 's'):

class Networkservergroup(models.Model):
    groupid = models.AutoField(db_column='GroupID', primary_key=True)  # Field name made lowercase.
    groupname = models.CharField(db_column='GroupName', unique=True, max_length=2048)  # Field name made lowercase.

    class Meta:
        managed = False
        db_table = 'NetworkServerGroups'

But when I come to run the test server, it complains about the following errors:

control_panel.Networkservergroup.groupname: (mysql.E001) MySQL does not allow unique CharFields to have a max_length > 255.

But clearly, mysql does support unique CharFields with a length of > 255, because the table was created perfectly fine using the SQL statement above.

How do I solve this problem?

2 Answers
Related