Mark Winterbottom Mark Winterbottom - 1 year ago 111
MySQL Question

Upgrading from Django 1.6 (with south) to 1.8 doesn't modify 'last_login' on the user table

I have upgraded from Django 1.6.5 (with south migrations) to Django 1.8. I have followed the instructions here:

So, I remove South, delete my previous migrations and run

python makemigrations
which makes a new migration file. Then I run
python migrate --fake-initial
to fake the initial migration. Then I run
python migrate

It all runs fine with no errors.

I have a custom user model which inherits
. In Django 1.8 it seems there is a change to the
field where it is now able to accept a
value (

The problem I have, is that the migration does not change the
field in the database table to accept null values. As a result, when I try and save I get a
(1048, "Column 'last_login' cannot be null")

How can I fix this? Do I need to manually change the field in the database, or is there a way to fix it with migrations?

When I run
python migrate --fake-initial
the output is this:
Running migrations:

Rendering model states... DONE
Applying contenttypes.0001_initial... FAKED
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0001_initial... FAKED
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying core.0001_initial... FAKED
Applying admin.0001_initial... FAKED
Applying sessions.0001_initial... FAKED

However, when I look in the database I still see
as not-null.

Answer Source

As noted in the 1.8 release notes:

If you are using a custom user model that inherits from AbstractUser, you’ll need to run makemigrations and generate a migration for your app that contains that model.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download