【发布时间】:2016-04-26 04:17:03
【问题描述】:
我复制了完整的示例代码:[customizing admin user][1](django 文档的一部分),但是当我运行它时,django 不会出现错误,但是当我添加用户时,django 会出现以下错误。 我没有更改示例的任何代码,并设置后续文档。 后续链接是示例: https://docs.djangoproject.com/en/1.8/topics/auth/customizing/#a-full-example
错误:
IntegrityError at /admin/app01/myuser/add/
NOT NULL constraint failed: app01_myuser.last_login
Request Method: POST
Request URL: http://127.0.0.1:8000/admin/app01/myuser/add/
Django Version: 1.8.5
Exception Type: IntegrityError
Exception Value:
NOT NULL constraint failed: app01_myuser.last_login
Exception Location: /Library/Python/2.7/site-packages/django/db/backends/sqlite3/base.py in execute, line 318
【问题讨论】:
-
您能描述一下您的目标吗? ?你在那个代码上还有什么改变?
-
是的,需要更多信息来解决此问题。确保您的数据库是最新的(进行迁移),因为从 1.7 -> 1.8 开始,last_login 字段的约束已更改,尽管这可能不会影响您的应用程序,我不知道!并确保您从 django.contrib.auth.models 导入用户。
-
我尝试使用新项目使用django文档中的相同代码,django(1.8)运行正常,但是在管理员保存用户时会出现错误,