2

Models.py

class UserManager(BaseUserManager):
    def create_user(self, email, password=None):
        if not email:
            raise ValueError('Users must have an email address')
        user = self.model(
            email=self.normalize_email(email),
        )

        user.set_password(password)
        user.save(using=self._db)
        return user


    def create_superuser(self, email, password):
        user = self.create_user(
            email,
            password=password,
        )
        user.staff = True
        user.admin = True
        user.save(using=self._db)
        return user


class User(AbstractBaseUser):
    email = models.EmailField(
        verbose_name='email address',
        max_length=255,
        unique=True,
    )
    is_active = models.BooleanField(default=True)
    staff = models.BooleanField(default=False)  # a admin user; non super-user
    admin = models.BooleanField(default=False)  # a superuser
    phone = models.IntegerField()
    
    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    def get_full_name(self):            
        return self.email

    def get_short_name(self):
        return self.email

    def __str__(self):
        return self.email

    def has_perm(self, perm, obj=None):
        return True

    def has_module_perms(self, app_label):
        return True

    @property
    def is_staff(self):
        return self.staff

    @property
    def is_admin(self):
        return self.admin

    objects = UserManager()

Settings.py

AUTH_USER_MODEL = 'Accounts.User'

Error:

return Database.Cursor.execute(self, query, params)                                                                 
django.db.utils.OperationalError: no such table: Accounts_user 

I have created a Model User, but when I tried to create a superuser, i got an error, that table does not exist, I have tried makemigrations and migrate command multiple times, but nothing seems to solve the issue

i can't even open the table even in the admin pannel, can someone help me solve this issue

  • Are there any errors when you try to construct these migrations (or migrate)? – Willem Van Onsem Nov 04 '21 at 20:53
  • Show your `settings.py` `INSTALLED_APPS` list. Do you register your app by relative path or by apps config file ? – mon io Nov 04 '21 at 21:44
  • Willem Van Onsem , there is no error while makemigrations magirate but error only come what creating superuser – Harish Kumar Nov 05 '21 at 03:35
  • settings.py `INSTALLED_APPS = [ 'Accounts', 'rest_framework', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', ]` – Harish Kumar Nov 05 '21 at 03:36
  • Repeated Question, try the solution from this : https://stackoverflow.com/q/24682155/16020090 – Uzzal H. Mohammad Nov 05 '21 at 05:04

2 Answers2

2

A small issue, using default command

manage.py makemigration
manage.py migrate

didn't update the Accounts App User table, so Have to Use

manage.py makemigration Accounts
manage.py migrate Accounts

This Solves the Error

0

I try to give a couple of tips:

  1. Make sure your model is in the Accounts app you created

  2. Check if the Accounts app is registered in settings.py

Leonardo
  • 2,439
  • 33
  • 17
  • 31