[Fixed]-How to fix migrations for an app with existing schema while not touching other apps?

1👍

From git point of view, you can do revert to previous commit.

git revert sha #commit sha of the last commit

OR

git reset --hard HEAD~n #n how many commits to remove.
git push --force

Fixing through django(possible if you didn’t add any migrations later.),

python manage.py makemigrations APP_A --empty
python manage.py makemigrations APP_A 
python manage.py migrate --fake

0👍

Unfortunately git revert didn’t help me. In the end, I solved the problem by executing the following steps:

1.Manually delete all tables related to the “A” app in db.sqlite3.

2.Create new migrations and db.sqlite3 tables from existing schema:

python manage.py makemigrations A --empty
python manage.py makemigrations A
python manage.py migrate

3.Dump the tables data back into db.sqlite3 from a backup:

sqlite3 ~/Backup/A/db.sqlite3 ".dump table_name" | grep -v "CREATE" | sqlite3 db.sqlite3
👤srgbnd

Leave a comment