Search code examples
djangopostgresqldjango-south

How big can I make email, first_name, last_name and username in auth.User?


I've lost an user today :(

An user tried to signup to my site and his email was bigger than 75 characters (Django's auth.User default), I'm working on a migration to fix that, but I wonder, how big can I make the column without having to worry about performance|storage|memory issues?

I use PostgreSQL and Django 1.3.1 on Heroku.

Here's the South migration I intend to run:

class Migration(SchemaMigration):

    def forwards(self, orm):
        # Changing User.username, User.email, User.first_name and User.last_name
        # to bigger fields
        db.alter_column('auth_user', 'username', models.CharField(max_length=255, unique=True))
        db.alter_column('auth_user', 'email', models.CharField(max_length=255, blank=True))
        db.alter_column('auth_user', 'first_name', models.CharField(max_length=255, blank=True))
        db.alter_column('auth_user', 'last_name', models.CharField(max_length=255, blank=True))

    def backwards(self, orm):
        db.alter_column('auth_user', 'username', models.CharField(max_length=30, unique=True))
        db.alter_column('auth_user', 'email', models.CharField(max_length=75, blank=True))
        db.alter_column('auth_user', 'first_name', models.CharField(max_length=30, blank=True))
        db.alter_column('auth_user', 'last_name', models.CharField(max_length=30, blank=True))

Solution

  • Using only migrations will leave problems associated with form validation, django.contrib.admin and etc.

    There is very similar question you can see here: Can django's auth_user.username be varchar(75)? How could that be done?

    There's also package than you can use to extend username field: https://github.com/GoodCloud/django-longer-username (based on that question)

    You can extend that code found in that package to extend email field too (since it extends only username field)