Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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: https://docs.djangoproject.com/en/1.8/topics/migrations/#upgrading-from-south

So, I remove South, delete my previous migrations and run python manage.py makemigrations which makes a new migration file. Then I run python manage.py migrate --fake-initial to fake the initial migration. Then I run python manage.py migrate.

It all runs fine with no errors.

I have a custom user model which inherits AbstractBaseUser. In Django 1.8 it seems there is a change to the last_login field where it is now able to accept a null value (https://docs.djangoproject.com/fr/1.8/ref/contrib/auth/#django.contrib.auth.models.User.last_login).

The problem I have, is that the migration does not change the last_login field in the database table to accept null values. As a result, when I try and save I get a IntegrityError saying (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?

Edit When I run python manage.py 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 user_last_login as not-null.

like image 391
LondonAppDev Avatar asked Apr 28 '15 07:04

LondonAppDev


1 Answers

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.

like image 108
Tim Graham Avatar answered Nov 14 '22 15:11

Tim Graham