6

I'm trying to use django-registration in my simple project.

settings.py

# DJANGO REGISTRATION
ACCOUNT_ACTIVATION_DAYS = 7
AUTH_USER_EMAIL_UNIQUE = True
EMAIL_HOST = 'localhost'
EMAIL_PORT = 1025
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_USE_TLS = False
DEFAULT_FROM_EMAIL = 'example@gmail.com'

urls.py

url(r'^accounts/', include('registration.backends.hmac.urls')),

Registration template:

{% extends "index.html" %}
{% block content %}
<h1>Registration</h1>
<form method="post" action="">
    {% csrf_token %}
    <dl class="register">
    {% for field in form %}
        <dt>{{ field.label_tag }}</dt>
        <dd class="clearfix">{{ field }}
        {% if field.help_text %}<div class="clearfix">{{ field.help_text }}</div>{% endif %}
        {% if field.errors %}<div class="myerrors clearfix">{{ field.errors }}</div>{% endif %}
        </dd>
    {% endfor %}
    </dl>
<input type="submit" value="Sign Up"  class="clearfix">
</form>
{% endblock %}

When I going to register new user, I get an error:

Django Version:     1.9c1
Exception Type:     IntegrityError
Exception Value:    (1048, "Column 'last_login' cannot be null")

I don't use 'CustomUser' model.

Stan Zeez
  • 1,138
  • 2
  • 16
  • 38
  • Related question (maybe a duplicate): [Upgrading from Django 1.6 (with south) to 1.8 doesn't modify 'last_login' on the user table](http://stackoverflow.com/questions/29913612/upgrading-from-django-1-6-with-south-to-1-8-doesnt-modify-last-login-on-the) – try-catch-finally Nov 21 '15 at 19:30
  • @try-catch-finally that question is a bit different, because that user had a custom user model. – Alasdair Nov 21 '15 at 20:28

2 Answers2

13

Make sure you have run all the migrations for the auth app. There is a migration 0005_alter_user_last_login_null.py that makes the last_login field optional.

Alasdair
  • 298,606
  • 55
  • 578
  • 516
  • I haven't changed anything in the auth app. – Stan Zeez Nov 21 '15 at 19:17
  • **Operations to perform:** Apply all migrations: admin, contenttypes, zeezmem, auth, sessions **Running migrations:** No migrations to apply. – Stan Zeez Nov 21 '15 at 19:20
  • 2
    The migration was added in Django 1.8, so it should be run when you upgrade from an earlier version of Django, even if you haven't changed the auth app. If Django already thinks the migration has been applied, you might need to drop the not null constraint manually. – Alasdair Nov 21 '15 at 20:24
  • Thanks, I delete record migraton from django_migrations table in my DB, and I have executed manage.py migrate and all migrations are was applied. And all is works. – Stan Zeez Nov 22 '15 at 07:36
  • How exactly do you delete the record migration? – Ofek Gila May 11 '16 at 05:30
  • @OfekGila I think it would probably be better to use the `--fake` command rather than deleting the record manually. You might find [this question](http://stackoverflow.com/questions/31953587/rerun-a-data-migration-on-django-1-8/31953632#31953632) useful. I don't know enough about the state of your migrations to give specific advice, so it would be better to start a new question rather than asking in the comments here. – Alasdair May 11 '16 at 07:39
5

Go to your database (MySQL Terminal):

$ mysql

mysql> SELECT * FROM django_migrations;

If you see some records, good. Delete them.

mysql> TRUNCATE TABLE django_migrations;

Leave MySQL terminal, and run the migrations again in django:

$ python manage.py migrate --fake-initial

Make sure this message appears:

0005_alter_user_last_login_null - [OK]

then you might see some other conflicts, that is fine because we only need to make this migration.

Restart your MySQL and Server and you're good to go.