Django - Tutorial 046. Reset migrations in the project

Django, Model, Reset

In the process of developing a project on Django, we may encounter an unpleasant situation when some packages and modules were removed and, accordingly, models from these packages were no longer used. But at the same time, squash of application migrations does not allow removing these packages, since migrations have many circular dependencies. As a result, removing unnecessary packages becomes a rather difficult task. Since resolving such dependencies becomes a non-trivial task. For me, such an unpleasant package was Django CKEditor, which was present almost everywhere. As a result, this package due to migrations remained for quite a long time in the list of requirements.txt, although in fact it was not used on the site at all.

In order to get rid of such dependencies of migrations, you need to delete all migrations, while not removing the content that was created by these migrations. And then create a new initial migration and apply it to the database also without making new changes to the database structure.

How to do it?

  1. Return all migrations to zero state with the fake parameter. This means that the migration information will be deleted, but the content will not change.

    python manage.py migrate app zero --fake

  2. Delete migration files from repository

    git rm "app/migrations/*"

  3. Create a new migration file

    python manage.py makemigrations app

  4. Start a new migration with the fake parameter to add information about the migration to the database, but not to change the database structure.

    python manage.py migrate app --fake

Conclusion

Carefully apply this approach to adjusting migrations and better create a new migration on the test server to make sure that you do everything correctly and the database will not broken.

At the same time, on the test server you can create a new migration and add it to the git repository..

Then on the production server you will need to do the following.

python manage.py migrate app zero --fake
git pull
python manage.py migrate app --fake

For Django, I recommend Timeweb VDS-server .

10% refund of hotel reservation amount on Booking
10% refund of hotel reservation amount on Booking
We offer a link with a 10% return on the amount of the order when booking a hotel through Booking
Support the author Donate

Comments

Only authorized users can post comments.
Please, Log in or Sign up
G
July 23, 2019, 3:47 a.m.
G0tzef

C++ - Test 001. The first program and data types

  • Result:66points,
  • Rating points-1
AS
July 22, 2019, 4:32 p.m.
Aleksandr Spiridonov

C++ - Test 001. The first program and data types

  • Result:46points,
  • Rating points-6
AS
July 22, 2019, 4:21 p.m.
Aleksandr Spiridonov

Qt - Test 001. Signals and slots

  • Result:73points,
  • Rating points1
Last comments
July 23, 2019, 12:14 p.m.
IscanderChe

Вот ссылка: https://github.com/iscander-che/TestReportViewer .
July 23, 2019, 5:42 a.m.
Evgenij Legotskoj

Хорошо, хотя конечно это С, а не С++ )))) Но если вдруг будут проблемы, то решение через класс со статическими переменными вы видели ))
July 23, 2019, 5:33 a.m.
IscanderChe

"Не потребует каждый раз объявлять extern в других файлах". И так не требует. У меня в тестовом классе эти переменные используются без дополнительного объявления. Так же объявил их в cpp-файле о…
July 23, 2019, 5:28 a.m.
IscanderChe

В репозиторий могу сегодня вечером выложить. "Или ее надо компилить самому под дистриб?" Тут я не совсем понимаю, что вы имеете ввиду. Я выложу в репозиторий исходный код утилиты, и всё.
July 23, 2019, 4:32 a.m.
Evgenij Legotskoj

Есть комментарий по вашему коду. Лучше бы вместо глобальных переменных в стиле Си, то есть с использоавнием extern, написали бы статические переменные в рамках класса. IMHO - это будет выглядеть…
Now discuss on the forum
July 23, 2019, 10:36 a.m.
Evgenij Legotskoj

Добрый день. Возможно, что проблема в поддержке OpenGL на виртуальной машине.
July 23, 2019, 8:20 a.m.
Mihailll

Так работает QFile f1(dbAdress); f1.setPermissions(QFileDevice::WriteOther);
July 23, 2019, 7:11 a.m.
Pavel K.

Советую использовать нечто такое или такое
July 22, 2019, 10:50 a.m.
Pavel K.

Благодарю.Буду пробовать.
Looking for a Job?
5,000.00 руб. - 15,000.00 руб.
Дизайнер
Moskovskiy, Moscow, Russia
25,000.00 руб. - 30,000.00 руб.
Разработчик Qt/C++
Barnaul, Altai Krai, Russia

For registered users on the site there is a minimum amount of advertising

EVILEG
About
Services
Join us
© EVILEG 2015-2019
Recommend hosting TIMEWEB