Search code examples
pythondjangodjango-upgrade

Issue upgrading Django from 1.8 to 1.9


I am trying to upgrade Django from 1.8 to 1.9 but, when I run migrations it's throwing up error. Below is the stack trace.

Stack trace

This is because of a new migration introduced in Django 1.9 which is to move auth username unicity logic from form to model [ref: ticket ]. But, before upgrading we have implemented a little hack mentioned here to increase username character length from the default 30 character length to 75 characters. Now, when I run migrations it's considering only the first 30 characters of username and throwing up Integrity Error. Is there a way around this ? I don't want to go for a custom auth model as there are lot of complications involved.


Solution

  • First, migrate to migration 0006 if you haven't already.

    ./manage.py migrate auth 0006_require_contenttypes_0002
    

    Then upgrade to Django 1.10 (or 1.11 LTS) once it's released, and fake migration 0007.

    ./manage.py migrate auth 0007_alter_validators_add_error_messages --fake
    

    This migration is trying to reduce the column from 75 characters to 30 characters, so it must be faked.

    Then, you can run the rest of the migrations for auth:

    ./manage.py migrate auth
    

    In particular, migration 0008 from Django 1.10 will increase the max length of the username to 150 characters. This means you can remove any hacks to alter the username max length that could cause problems.

    To be on the safe side, I wouldn't recommend faking 0007 and upgrading to Django 1.9. I have no idea whether faking the migration and keeping your username length hack would work or cause problems I haven't thought of.