Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What to do with unapplied migrations in Django?

Currently I have converted my python 2 project into python 3 project & earlier I was using Django version 1.9.13 & now I have updated it to 2.2.6.

Now I am able to run my project in latest version of python and django but when I run my project in cmd I have found that It showing message like You have 253 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s)... so I have checked my migrations folder and able to find all migrations files there.

Any idea why I am getting such kind of message here & if it is bug then what should I do to get rid of such problem ?

Thanks.

like image 325
Moon Avatar asked Dec 09 '19 12:12

Moon


People also ask

How do I get rid of unapplied migrations?

Yes, you can just delete them from migrations folder (dont delete the migrations folder itself).

How do I see unapplied migrations in Django?

Solution for unapplied migration(s) To run the migrate comment: First, stop the Django server by pressing the keys CONTROL-C. Then run the comment python manage.py migrate in the same integrated terminal or a new one. Now you can see all the required migrations applied to the apps.

Should I delete migrations Django?

Deleting Django migrations is generally a bad idea. Django keeps track of what's in your db through these migration files, as well as through a table it creates in your db, and if you delete any of this Django will start throwing errors on migrate that can be hard to fix.


1 Answers

You need to migrate those migrations to your database. This means you have changes in your model classes but they are not applied to the database you are using. To migrate to the database: in CMD

python manage.py makemigrations
python manage.py migrate

In both cases, make sure you are inside your virtualenv (if you have one) and using the right python. For instance, in most cases if you have multiple pythons installed (2 and 3); you might have to use 'python3' in the above commands.

like image 143
Menilik Belay Woldeyes Avatar answered Oct 27 '22 07:10

Menilik Belay Woldeyes