Reputation: 657
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. :)
Upvotes: 8
Views: 8287
Reputation: 91
(if not in production and afford to loose data)
You will get a new database file and with fixed migration.
Happy Django user !!
Upvotes: 1
Reputation: 786
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.
Upvotes: 1
Reputation: 2470
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
Upvotes: 16
Reputation: 8222
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.
Upvotes: 0
Reputation: 357
Try these following steps:
python manage.py clear_pyc
__init__.py
file insidepython 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
Upvotes: -1
Reputation: 9
Delete everything under the migrations folder
and type the following command
python manage.py makemigrations
Upvotes: -2