本文介绍了如何解决django.db.utils.IntegrityError:(1364,“字段'name'没有默认值"))的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于尝试为Django项目创建超级用户而出现此错误.不确定哪个表的名称"列需要默认值.

I'm getting this error from trying to create a superuser for my Django project. Unsure what table requires a default value for its 'name' column.

为我的Django项目成功创建迁移后,我运行了 python manage.py createsuperuser 创建超级用户,并收到以下错误: django.db.utils.IntegrityError:(1364,字段'name'没有默认值").我安装了mysql(8.0),正在OSX上使用自制软件,并在虚拟环境中使用python 3.

After successfully creating migrations for my Django project I ran python manage.py createsuperuser to create the superuser and got the following error:django.db.utils.IntegrityError: (1364, "Field 'name' doesn't have a default value"). I installed mysql (8.0) am using homebrew on OSX and using python 3 in a virtual env.

我不确定上面的命令尝试使用哪个数据库,更不用说哪个表了.无论如何,我已经遍历了数据库中与项目相关的所有表以及 mysql 数据库中的所有表,并在找到的唯一名称列上运行了此命令:

I'm not sure which database the above command tries to engage, talk less of which table. In any case I have gone through all tables in the db relevant to my project as well as in the mysql database and have run this command on the only name column found:

ALTER TABLE django_migrations ALTER列名SET DEFAULT'-'

但是我仍然收到此错误.我已经阅读了Django文档中的createsuperuser,并研究了一些Django代码,但解决该问题的价值很小.任何帮助,将不胜感激.

But I am still getting this error. I have read up on createsuperuser in the Django docs as well as looked into some of the Django code but have gleaned very little of value to solving this. Any help with this would be greatly appreciated.

推荐答案

尝试:

ALTER TABLE django_content_type MODIFY COLUMN name character varying(50) NOT NULL DEFAULT 'not null';

或者如果您希望它为空:

Or if you want it to be empty:

ALTER TABLE django_content_type MODIFY COLUMN name character varying(50) NOT NULL DEFAULT '';

来自此处: https://github.com/arteria/django-background-tasks/issues/139

这篇关于如何解决django.db.utils.IntegrityError:(1364,“字段'name'没有默认值"))的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 10:39