django server error create superuser

I get the following error when I want to create superuser
Previously I have completely deleted the bbdb and recreated it.

python createsuperuser

You have 9 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, reclamaciones, sessions, usuario.
Run 'python migrate' to apply them.
Nombre de usuario: albert
Traceback (most recent call last):
  File "C:\Users\apenaranda\Desktop\Python_Intranet\env\Lib\site-packages\django\db\backends\", line 89, in _execute
    return self.cursor.execute(sql, params)
  File "C:\Users\apenaranda\Desktop\Python_Intranet\env\Lib\site-packages\django\db\backends\sqlite3\", line 357, in execute
    return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: no such table: usuario_usuario

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

Traceback (most recent call last):
  File "C:\Users\apenaranda\Desktop\Python_Intranet\", line 22, in <module>
  File "C:\Users\apenaranda\Desktop\Python_Intranet\", line 18, in main
  File "C:\Users\apenaranda\Desktop\Python_Intranet\env\Lib\site-packages\django\core\management\", line 446, in execute_from_command_line
  File "C:\Users\apenaranda\Desktop\Python_Intranet\env\Lib\site-packages\django\core\management\", line 440, in execute
  File "C:\Users\apenaranda\Desktop\Python_Intranet\env\Lib\site-packages\django\core\management\", line 402, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\apenaranda\Desktop\Python_Intranet\env\Lib\site-packages\django\contrib\auth\management\commands\", line 88, in execute
    return super().execute(*args, **options)
  File "C:\Users\apenaranda\Desktop\Python_Intranet\env\Lib\site-packages\django\core\management\", line 448, in execute
    output = self.handle(*args, **options)
  File "C:\Users\apenaranda\Desktop\Python_Intranet\env\Lib\site-packages\django\contrib\auth\management\commands\", line 130, in handle
    error_msg = self._validate_username(
  File "C:\Users\apenaranda\Desktop\Python_Intranet\env\Lib\site-packages\django\contrib\auth\management\commands\", line 297, in _validate_username
  File "C:\Users\apenaranda\Desktop\Python_Intranet\env\Lib\site-packages\django\contrib\auth\", line 46, in get_by_natural_key
    return self.get(**{self.model.USERNAME_FIELD: username})
  File "C:\Users\apenaranda\Desktop\Python_Intranet\env\Lib\site-packages\django\db\models\", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "C:\Users\apenaranda\Desktop\Python_Intranet\env\Lib\site-packages\django\db\models\", line 646, in get
    num = len(clone)
  File "C:\Users\apenaranda\Desktop\Python_Intranet\env\Lib\site-packages\django\db\models\", line 376, in __len__
  File "C:\Users\apenaranda\Desktop\Python_Intranet\env\Lib\site-packages\django\db\models\", line 1867, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "C:\Users\apenaranda\Desktop\Python_Intranet\env\Lib\site-packages\django\db\models\", line 87, in __iter__
    results = compiler.execute_sql(
  File "C:\Users\apenaranda\Desktop\Python_Intranet\env\Lib\site-packages\django\db\models\sql\", line 1398, in execute_sql
    cursor.execute(sql, params)
  File "C:\Users\apenaranda\Desktop\Python_Intranet\env\Lib\site-packages\django\db\backends\", line 103, in execute
    return super().execute(sql, params)
  File "C:\Users\apenaranda\Desktop\Python_Intranet\env\Lib\site-packages\django\db\backends\", line 67, in execute
    return self._execute_with_wrappers(
  File "C:\Users\apenaranda\Desktop\Python_Intranet\env\Lib\site-packages\django\db\backends\", line 80, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "C:\Users\apenaranda\Desktop\Python_Intranet\env\Lib\site-packages\django\db\backends\", line 84, in _execute
    with self.db.wrap_database_errors:
  File "C:\Users\apenaranda\Desktop\Python_Intranet\env\Lib\site-packages\django\db\", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "C:\Users\apenaranda\Desktop\Python_Intranet\env\Lib\site-packages\django\db\backends\", line 89, in _execute
    return self.cursor.execute(sql, params)
  File "C:\Users\apenaranda\Desktop\Python_Intranet\env\Lib\site-packages\django\db\backends\sqlite3\", line 357, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: usuario_usuario

The table does exist in the database
Thank you

This occurred to be migrations error. when you have deleted your database, did you reset your migrations as well or not.

Process I have followed:

  • delete the databases


python makemigrations
python migrate --database users_db  
python migrate --database intranet_db

then i execute
python createsuperuser

and then I get all the errors.
If I access my database server, it does exist.

After this step you should have reset you migrations that are generated when you run this below commands

for resetting migrations How to Reset Migrations take reference from here.

I do not see what is different in this link that you attach, I have done the same

There is lot of difference, if you have read it properly.

After deleting database you should have run this below command

find . -path "*/migrations/*.py" -not -name "" -delete
find . -path "*/migrations/*.pyc"  -delete

This will delete the old migrations.
Note:- when you run above commands for reset migrations after that uninstall and reinstall django

After that you should have run these commands

python makemigrations
python migrate --database users_db  
python migrate --database intranet_db

I have removed everything from the /migrations/ folder because the command

find . -path "*/migrations/*.py" -not -name "" -delete

it gave me error: FIND: wrong parameter format

Then I uninstall and install again and execute the previous commands:

python makemigrations
python migrate --database users_db
python migrate --database intranet_db

The same thing comes out:

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

The migrations are done correctly and upload everything to the database.

This command is for unix-like OS, so if you are using windows or any other OS please specify

Also deleted the files?
If yes than this file should have to be there in the migrations folder for each app where models are defined.

The init files have not been removed.
I’m with windows yes.

In the end I was able to register the superuser with the command:

python createsuperuser --database=users_db

Thanks for everything.

Please do not recommend this as a general step. It is not necessary when the migration files themselves are ok, and likely dangerous in projects with non-generated migration files.

The appropriate first step after dropping and recreating a database would be to simply run the makemigrations/migrate combo to see if the existing migrations will recreate the schema.

I’ll keep this in mind. Thanks for guiding :v: