# Auth - createsuperuser error

**URL:** <https://forum.codewithmosh.com/t/auth-createsuperuser-error/8844>\
**Category:** Django\
**Created:** [November 29, 2021, 5:32pm UTC](https://forum.codewithmosh.com/t/auth-createsuperuser-error/8844 "2021-11-29T17:32:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JayDub](https://avatars.discourse-cdn.com/v4/letter/j/e9bcb4/32.png) [@JayDub](https://forum.codewithmosh.com/u/JayDub)\
**Post date:** [November 29, 2021, 5:32pm UTC](https://forum.codewithmosh.com/t/auth-createsuperuser-error/8844/1 "2021-11-29T17:32:34Z")

</div>

When applying the AbstractUser changes to the User class (in models.py and admin.py) I was encountering an error when running the _python manage.py createsuperuser_ command.

Error:  
TypeError: UserManager.create\_superuser() missing 1 required positional argument: ‘username’

Temporary Solution:

> **[How to Use Email as Username for Django Authentication](https://tech.serhatteker.com/post/2020-01/email-as-username-django/)**
>
> 0: Intro The aim of this post will be explaining how to create a custom User Model in Django. So we can use that email address as the primary ‘user identifier’ instead of a username for authentication.
> Default Django app will give you a User Model...

I would love any feedback as to why this error was appearing (I’m using sql server 2016 and also had a User table previously made).

Hopefully someone can fill me in as to why this was happening. It certainly makes sense as to why this solution works, but as to why Mosh’s demonstration was working, I couldn’t find under the hood what was causing mine to break.

Either way , I hope this helps someone in the future, trying to follow this video with an existing app.

---

<div class="post-metadata">

**Author:** ![some\_random\_coder](https://avatars.discourse-cdn.com/v4/letter/s/3be4f8/32.png) [@some\_random\_coder](https://forum.codewithmosh.com/u/some_random_coder)\
**Post date:** [November 30, 2021, 3:24am UTC](https://forum.codewithmosh.com/t/auth-createsuperuser-error/8844/2 "2021-11-30T03:24:27Z")

</div>

Are you saying that you started your project using Django’s built-in User model and you are trying to swap it out with your custom user model? If so, this ain’t straightforward because Django already set up a bunch of things assuming you are using the built-in user model. So, you have to change your code as well as the database schema.

Things are better explained [here](https://ruddra.com/django-custom-user-migration-mid-phase-project/) and here  
Also, Mosh does go through this in part 2 user auth chapter.

---

<div class="post-metadata">

**Author:** ![JayDub](https://avatars.discourse-cdn.com/v4/letter/j/e9bcb4/32.png) [@JayDub](https://forum.codewithmosh.com/u/JayDub)\
**Post date:** [November 30, 2021, 1:56pm UTC](https://forum.codewithmosh.com/t/auth-createsuperuser-error/8844/3 "2021-11-30T13:56:36Z")

</div>

No, it was my own custom user model. I was able to fix the problem, but unfortunately I don’t understand why.

In the admin.py file of the app where my user table lives, I changed:

@admin.register(UserAdmin)  
class UserAdmin(BaseUserAdmin):

To:  
class UserAdmin(BaseUserAdmin):  
code  
code  
admin.site.register(User, UserAdmin)

I originally tried @admin.resgister(User, UserAdmin) with no luck. Again, I am unsure as to why the second option worked for me, but figured I would update my fix because it is more inline with the course and a better solution than the linked option that I posted previously.

Again, I’d like to state that I am going thru this video and implementing some of Mosh’s techniques into my own project, and not following along with his project. Hopefully this can help someone get un-stuck in the future.

---

<div class="post-metadata">

**Author:** ![some\_random\_coder](https://avatars.discourse-cdn.com/v4/letter/s/3be4f8/32.png) [@some\_random\_coder](https://forum.codewithmosh.com/u/some_random_coder)\
**Post date:** [November 30, 2021, 4:36pm UTC](https://forum.codewithmosh.com/t/auth-createsuperuser-error/8844/4 "2021-11-30T16:36:14Z")

</div>

Oh, I see what you mean now. But without looking at your code, this is as far as I can tell.

Django’s `createsuperuser` command calls the `create_superuser()` method from your UserManager. The default UserManager requires you to pass the username to create a superuser.

The problem you are having is that the user data collected from `createsuperuser` command didn’t include the field called `username`. Chances are you are not requiring username.

Now, why did this happen? this is the part that tricks me. Normally, if your custom user model extends AbstractUser, you are guaranteed to have a username field. So, there must be some other things that you are doing, which I can’t tell without looking at the code.

The solution you posted works because it has every necessary bit. The user extends AbstractBaseUser, specified USERNAME\_FIELD, and implemented a custom user manager.
