创建超级用户时,Django 2.1 NOT NULL约束失败 [英] Django 2.1 NOT NULL Constraint Failed When Creating Super User

查看:67
本文介绍了创建超级用户时,Django 2.1 NOT NULL约束失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Django几个月了,没有任何问题,但是当我创建一个新项目并添加超级用户时,出现以下错误:

I've been using Django for several months now without any issue but when I went to create a new project and add the super-user, I get the following error:

django.db.utils.IntegrityError: NOT NULL constraint failed: auth_user.last_login

所有迁移已成功创建并应用.我已将数据库破坏并重新创建了六次,但无济于事.应用程序迁移可以毫无问题地运行,这是我第一次在Django项目中遇到此问题.

All migrations have been created and applied successfully. I have destroyed and recreated the database a half dozen times to no avail. App migrations run without any problem whatsoever and this is the first time I've encountered this issue in an Django project.

推荐答案

我刚刚意识到此消息被埋在数十行错误消息中:

I just realized this message was buried in the dozens of lines of error messages:

您有12个未应用的迁移.在为应用程序应用迁移之前,您的项目可能无法正常工作:管理员,身份验证,内容类型,会话.运行"python manage.py migration"以应用它们.

You have 12 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions. Run 'python manage.py migrate' to apply them.

仅运行 manage.py迁移和/或 manage.py迁移应用程序名称并没有应用所需的系统迁移.出于某种原因,这次我不得不单独做一个.

Running just manage.py migrate and/or manage.py migrate appname did not apply the required system migrations. I had to do each one individually this time for some reason.

单独运行每个用户之后,我可以毫无问题地创建一个超级用户:

After running each one individually I was able to create a superuser without a problem:

manage.py migrate admin
manage.py migrate auth
manage.py migrate contenttypes
manage.py migrate sessions

但是,我从来没有做过此事.如果有人知道发生这种情况的原因,我很想知道,但是我现在已经解决了主要问题.

I've never had to do that before, however. If anyone knows a reason as to why that happened I'd love to know but I've solved the main issue for now.

这篇关于创建超级用户时,Django 2.1 NOT NULL约束失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆