Django.db.utils.OperationalError: no such table: App_useraccount

from django.db import models
from django.db import models
from django.contrib.auth.models import (AbstractBaseUser,
                                        BaseUserManager, PermissionsMixin )


class MyAccountManager(BaseUserManager):
    def create_user(self, first_name, last_name, email,username,password=None):
        if not email:
            raise ValueError('user must have an email address')
        if not username:
            raise ValueError('user must have an username')

        user = self.model(
            email = self.normalize_email(email),
            username = username,
            first_name = first_name,
            last_name = last_name,
        )
        user.set_password(password)
        user.save(using=self._db)
        return user

    def create_superuser(self, first_name, last_name,username, email, password):
        user = self.create_user(
            email = self.normalize_email(email),
            username = username,
            password = password,
            first_name = first_name,
            last_name = last_name
        )
        user.is_admin = True
        user.is_active = True
        user.is_staff = True
        user.is_superadmin = True
        user.save(using=self._db)
        return user

class UserAccount(AbstractBaseUser,PermissionsMixin):
    first_name      = models.CharField(max_length=64)
    last_name       = models.CharField(max_length=64)
    username        = models.CharField(max_length=64, unique=True)
    email           = models.EmailField(max_length=64, unique=True)
    state           = models.CharField(max_length=30)
    city            = models.CharField(max_length=30)
    phone_number    = models.CharField(max_length=20)
    address         = models.CharField(max_length=80)
    dob             = models.CharField(max_length=50)
    gender          = models.CharField(max_length=30)
    min_salary      = models.IntegerField(null=True)
    max_salary      = models.IntegerField(null=True)
    profile_pic     = models.ImageField(upload_to='app/img/condidate')

    # required_fields

    date_joined     = models.DateTimeField(auto_now_add=True)
    last_login      = models.DateTimeField(auto_now_add=True)
    is_admin        = models.BooleanField(default=False)
    is_staff        = models.BooleanField(default=False)
    is_active       = models.BooleanField(default=False)
    is_superadmin   = models.BooleanField(default=False)

    USERNAME_FIELD  = 'email'
    REQUIRED_FIELDS = ['username','first_name','last_name']

    objects = MyAccountManager()

    def __str__(self):
        return self.email

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

    def has_module_perms(self, add_label):
        return True

class Company(models.Model):
    user_id      = models.ForeignKey(UserAccount, on_delete=models.CASCADE)
    post_by      = models.CharField(max_length=60)
    company_name = models.CharField(max_length=150)
    date_of_post = models.DateTimeField(auto_now_add=True)
    discription  = models.TextField(max_length=1000)
    contact      = models.CharField(max_length=60)
    address      = models.CharField(max_length=150)
    logo_pic     = models.ImageField(upload_to="app/img/company")

    class Meta:
        verbose_name_plural = 'Companies'

**i want to add some fields to my models so i deleted the sqlite3 database and initial001 file then added extra fields to existing models and run the makemigration and migrate when i run createsuperuser it will showing this error

(myenv) C:\Users\Omkar\JobFind_Project\omkar>py manage.py createsuperuser
Email: sms88864@gmail.com       
Traceback (most recent call last):
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\backends\utils.py", line 89, in _execute  
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\backends\sqlite3\base.py", line 357, in execute
    return Database.Cursor.execute(self, query, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sqlite3.OperationalError: no such table: App_useraccount

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\Omkar\JobFind_Project\omkar\manage.py", line 22, in <module>
    main()
  File "C:\Users\Omkar\JobFind_Project\omkar\manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\core\management\__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\core\management\__init__.py", line 440, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\core\management\base.py", line 402, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 88, in execute
    return super().execute(*args, **options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\core\management\base.py", line 448, in execute
    output = self.handle(*args, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 130, in handle
    error_msg = self._validate_username(
                ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 297, in _validate_username
    self.UserModel._default_manager.db_manager(database).get_by_natural_key(
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\contrib\auth\base_user.py", line 46, in get_by_natural_key
    return self.get(**{self.model.USERNAME_FIELD: username})
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\models\manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\models\query.py", line 646, in get        
    num = len(clone)
          ^^^^^^^^^^
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\models\query.py", line 376, in __len__    
    self._fetch_all()
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\models\query.py", line 1866, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\models\query.py", line 87, in __iter__    
    results = compiler.execute_sql(
              ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\models\sql\compiler.py", line 1398, in execute_sql
    cursor.execute(sql, params)
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\backends\utils.py", line 103, in execute  
    return super().execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\backends\utils.py", line 67, in execute   
    return self._execute_with_wrappers(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\backends\utils.py", line 80, in _execute_with_wrappers
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\backends\utils.py", line 89, in _execute  
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\backends\utils.py", line 89, in _execute  
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\backends\sqlite3\base.py", line 357, in execute
    return Database.Cursor.execute(self, query, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django.db.utils.OperationalError: no such table: App_useraccount

(myenv) C:\Users\Omkar\JobFind_Project\omkar>

(myenv) C:\Users\Omkar\JobFind_Project\omkar>py manage.py makemigrations 
No changes detected

(myenv) C:\Users\Omkar\JobFind_Project\omkar>py manage.py migrate        
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
  No migrations to apply.

(myenv) C:\Users\Omkar\JobFind_Project\omkar>py manage.py createsuperuser
Email: sms88864@gmail.com
Traceback (most recent call last):
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\backends\utils.py", line 89, in _execute  
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\backends\sqlite3\base.py", line 357, in execute
    return Database.Cursor.execute(self, query, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sqlite3.OperationalError: no such table: App_useraccount

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\Omkar\JobFind_Project\omkar\manage.py", line 22, in <module>
    main()
  File "C:\Users\Omkar\JobFind_Project\omkar\manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\core\management\__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\core\management\__init__.py", line 440, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\core\management\base.py", line 402, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 88, in execute
    return super().execute(*args, **options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\core\management\base.py", line 448, in execute
    output = self.handle(*args, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 130, in handle
    error_msg = self._validate_username(
                ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 297, in _validate_username
    self.UserModel._default_manager.db_manager(database).get_by_natural_key(
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\contrib\auth\base_user.py", line 46, in get_by_natural_key
    return self.get(**{self.model.USERNAME_FIELD: username})
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\models\manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\models\query.py", line 646, in get
    num = len(clone)
          ^^^^^^^^^^
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\models\query.py", line 376, in __len__    
    self._fetch_all()
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\models\query.py", line 1866, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Omkar\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\backends\sqlite3\base.py", line 357, in execute
    return Database.Cursor.execute(self, query, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^django.db.utils.OperationalError: no such table: App_useraccount

**

i added extra fields to that models so want to run migrate and makemigrate and createsuperuser successfully

Back to Top