I try to create a superuser but the error is no such table: users_user

Viewed 48

the error is :

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

this is my model:

class User(AbstractUser):
pass

the settings:

AUTH_USER_MODEL = 'users.User'
3 Answers

Delete all migrations then... apply below commands

python manage.py makemigrations yourapp_name
python manage.py migrate

First delete all migrations file and then add below code and then do migrations

try this:

    from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin   
    class User(AbstractBaseUser, PermissionsMixin):
             pass

You may need to remove the migration folders of your apps and then type the following to reset all admin, auth, contenttypes, and sessions from the migration history and drop the tables:

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

Then, just do makemigrations users and migrate users.

Related