简体   繁体   English

django-registration(1048,“Column'last_login'不能为null”)

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

I'm trying to use django-registration in my simple project. 我正在尝试在我的简单项目中使用django-registration。

settings.py 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 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. 我不使用'CustomUser'模型。

Make sure you have run all the migrations for the auth app. 确保您已运行auth应用程序的所有迁移。 There is a migration 0005_alter_user_last_login_null.py that makes the last_login field optional. 迁移0005_alter_user_last_login_null.py使last_login字段可选。

Go to your database (MySQL Terminal): 转到您的数据库(MySQL终端):

$ 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: 离开MySQL终端,再次在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. 重新启动你的MySQL和服务器,你很高兴。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM