pythondjangodatabase

Python Django sees old migrations but everything was deleted


I cleared all my database, even created new with different name, deleted all migrations and migrations folder in every app of my django project, cleared all images, containers, volumes and builds in my Docker. But when I am running
python manage.py showmigrations

it shows me my old migrations, but I have no idea where does it finds them, because I deleted everything I could.
and when I am running
python manage.py makemigrations
it returns me message "No changes detected"

I even changed database name to new one.

I deleted everything and just wanted to start from zero, but somehow it finds old migrations that doesn't even exist. enter image description here


Solution

  • Django stores migration history in table djnago_migrations in DB, that's why you're seeing this error

    First of all delete all your migrations, you can use this following command

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

    Then unistall django and the again install it. Once it's done open your python db shell and delete migrations table from your DB and then create new fresh migrations and then migrate

    python manage.py dbshell
    
    DROP TABLE django_migrations;
    
    python3 manage.py makemigrations
    
    python3 manage.py migrate
    
    

    This is the most effective way I found out to get rid out of this error. Note Just be cautious while doing this take your DB backup first before doing this