6

I am using Django, and Postgre for the DB. So I was done with all the migrations, but then I accidentally deleted the migrations folder in my editor. So I did the 'python manage.py makemigrations' again in the terminal, hoping I can get the folder back, but it replied 'No changes detected.' What should I do to get the folder back? Is it wrong to just simply make migrations again? I've tried creating a new database and re-do the same process, but it still says 'No changes detected.'

I very much appreciate your help. :)

Ryan Oh
  • 597
  • 5
  • 21

5 Answers5

13

If you have deleted all migrations then you have to reset the migrations and create again. don't worry, your DB will be safe.
Follow the below steps if you want to fix the migrations without loosing the database.

First Clear database migration history.

a. go to python shell python manage.py shell

b. type from django.db.migrations.recorder import MigrationRecorder

c. type MigrationRecorder.Migration.objects.all().delete()

Second, recreate migrations

Create a new folder migrations. Create a file named __init__.py inside the folder.

Run command python manage.py makemigrations.

Apply fake migration so your database schema and migration history sync.

python manage.py migrate --fake

Ajay saini
  • 2,352
  • 1
  • 11
  • 25
0

I have found this recipe (Scenario 2, to keep the existing development DB) works well. It can be applied to a single app, which is possibly trickier than resetting migrations on all apps at once.

nigel222
  • 7,582
  • 1
  • 14
  • 22
  • Didn't work. Getting "No changes detected", every time. I tried different Scenarios. The one where you delete "db.sqlite3", I do not recommend to use, unless you have no problem creating a new superuser, because it will delete it. – AnonymousUser Jul 14 '21 at 03:55
0

I now found the solution on Django - makemigrations - No changes detected

The solution was:

python3 manage.py makemigrations yourAppName

This is for macOS.

If you use Windows it's probably

py manage.py makemigrations yourAppName

and "yourAppName" should be the name of your app, not the same as in the example, only if your apps name is actually "yourAppName", then of course that will work.

AnonymousUser
  • 690
  • 7
  • 26
-1

Try these following steps:

  1. clear pyc cache: run python manage.py clear_pyc
  2. Create new migrations folder if the old one is deleted and create an __init__.py file inside
  3. Create the migrations again by running python manage.py makemigrations <your-app-name>

Like that you will recover the deleted migration, as you can migrate afterwards everything by running python manage.py migrate

SOF
  • 347
  • 1
  • 4
  • 18
-2

Delete everything under the migrations folder

and type the following command

python manage.py makemigrations