django-registration (1048, “Column 'last_login' cannot be null”)

本秂侑毒 提交于 2019-12-09 18:10:41

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/33847110/django-registration-1048-column-last-login-cannot-be-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!