views:

412

answers:

2

I am having an issue with the django.contrib.auth User model where the email max_length is 75.

I am receiving email addresses that are longer than 75 characters from the facebook api, and I need to (would really like to) store them in the user to continuity among users that are from facebook connect and others.

I am able to solve the problem of "Data truncated for column 'email' at row 1" by manually going editing the field in our mySql database, but is there a better way to solve this? preferably one that does not involve me manually editing the database every time I reset it for a schema change?

I'm ok with editing the database as long as I can add it to the reset script, or the initial_data.json file

Thanks, Jim

+6  A: 

EmailField 75 chars length is hardcoded in django. You can fix this like that:

from django.db.models.fields import EmailField
def email_field_init(self, *args, **kwargs):
  kwargs['max_length'] = kwargs.get('max_length', 200)
  CharField.__init__(self, *args, **kwargs)
EmailField.__init__ = email_field_init

but this will change ALL EmailField fields lengths, so you could also try:

from django.contrib.auth.models import User
from django.utils.translation import ugettext as _
from django.db import models
User.email = models.EmailField(_('e-mail address'), blank=True, max_length=200)

both ways it'd be best to put this code in init of any module BEFORE django.contrib.auth in your INSTALLED_APPS

romke
ick... that sucks :( why does facebook give me these gigantic email addresses?
Jiaaro
well, kinda sucks, anyway you have other choice: write your own django.contrib.auth module (which btw isn't worst thing to do if you see more troubles like this with buildin auth)
romke
+1  A: 

There is now a ticket to increase the length of the email field in Django: http://code.djangoproject.com/ticket/11579

Graham King