MySQL error when trying to run tests with utf8mb4 charset

67 views
Skip to first unread message

fle...@fletchowns.net

unread,
Oct 16, 2013, 2:01:45 PM10/16/13
to django...@googlegroups.com
Hello!

I tried to run ./manage.py test for the first time and I got the following error:

DatabaseError: (1071, 'Specified key was too long; max key length is 767 bytes')

Looking at the log in MySQL, it appears to be caused by this statement:

CREATE TABLE `auth_customuser` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `password` varchar(128) NOT NULL,
    `last_login` datetime NOT NULL,
    `email` varchar(255) NOT NULL UNIQUE,
    `is_active` bool NOT NULL,
    `is_admin` bool NOT NULL,
    `date_of_birth` date NOT NULL
)

So the email field of varchar(255) is causing me to go over the single-column index of 767 bytes in InnoDB when the charset is utf8mb4, that part I understand.

Why is it trying to create this auth_customuser table anyways though? It doesn't exist in my application normally. The email field on my auth_user table is varchar(75) so no error from that, not sure why it's a different length there though.

To get around the issue temporarily I set the database engine to sqlite, but I'd like to be able to use MySQL for the tests, since that's what my application normally uses.

Thanks in advance!

fle...@fletchowns.net

unread,
Oct 18, 2013, 7:30:10 PM10/18/13
to django...@googlegroups.com
Looks like this comes from custom_user.py in django.contrib.auth.tests:

class CustomUser(AbstractBaseUser):
    email = models.EmailField(verbose_name='email address', max_length=255, unique=True)
    is_active = models.BooleanField(default=True)
    is_admin = models.BooleanField(default=False)
    date_of_birth = models.DateField()

I think this should have the same length as AbstractUser, where it does not specify a max_length, so it defaults to 75 in django.db.models.fields.EmailField. Should I submit a pull request for this change?

Thanks!

tim

unread,
Oct 22, 2013, 2:20:52 PM10/22/13
to django...@googlegroups.com
I think you may be barking up the wrong tree, see https://code.djangoproject.com/ticket/21196
Reply all
Reply to author
Forward
0 new messages