0

I am working on my Final Year Project. I wanted to extend the default User model that Django provides in order to add some more attributes. I added following code in my models.py

class User(AbstractUser):
    contact = models.CharField(max_length=100)

Also in settings.py I added:

AUTH_USER_MODEL = 'esacp.User'

where esacp is the name of my app.

After doing all of this, I ran python manage.py makemigrations esacp, then I ran python manage.py migrate in my Windows Command Prompt. Both of these commands worked perfectly.

Now, I went to create an admin role for my Django Web App, in order to manage the things as a superuser, when I ran the command python manage.py createsuperuser, it asked me for the username, after I entered username and pressed 'Enter', it gave me the error:

django.db.utils.OperationalError: no such table: esacp_user

A screenshot of the whole error:

enter image description here

Where did I make a mistake or miss anything?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Khubaib Khawar
  • 51
  • 1
  • 11
  • Does this answer your question? [django: User Registration with error: no such table: auth\_user](https://stackoverflow.com/questions/24682155/django-user-registration-with-error-no-such-table-auth-user) – mkrieger1 Feb 13 '20 at 09:43
  • @mkrieger1 it does not answer my question as I have just installed Django and made few Models in models.py, and tried to extend the default User Model provided by Django, and it is not creating superuser when I try to. – Khubaib Khawar Feb 13 '20 at 11:44
  • Can you post the migration file that was created after you ran `makemigrations` – Joe Feb 13 '20 at 14:53

2 Answers2

1

I think this error raise after shifting the Default user model to CustomUserModel

----- Follow those steps ------

1 - Delete (migrations) folder
2 - Delete (db.sqlite3) databse
3 - Run command (python manage.py makemigrations your_appname)
4 - Run command (python manage.py migrate)
5 - Run command (python manage.py createsuperuser)
0

Refer to this article for the best help!! It worked for me.Real Python

After Creating your Django project, change your directory -

cd (your PROJECT NAME)

And then run the following commands-

python manage.py migrate
python manage.py createsuperuser
Username:
Email:
Password :
Password(again) :