How to resolve django.db.utils.IntegrityError: (1364, "Field 'name' doesn't have a default value")

Viewed 3087

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.

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.

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 COLUMN name SET DEFAULT '-'

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.

2 Answers

Try:

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 '';

Taken from here: https://github.com/arteria/django-background-tasks/issues/139

By default Django has a table called auth_user serving the user authentication which doesn't contain a field called name, so my assumption is that you have a custom AUTH_USER_MODEL defined in your settings.py which contains a field called name with not set default value.

Related