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 .

We recommend hosting TIMEWEB
We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.
Support the author Donate

Comments

Only authorized users can post comments.
Please, Log in or Sign up
Looking for a Job?
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

DSh
Sept. 21, 2019, 2:55 p.m.
Dmitrij Shilkov

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

  • Result:46points,
  • Rating points-6
s
Sept. 18, 2019, 5:19 p.m.
sanyalitv

C++ - Test 002. Constants

  • Result:33points,
  • Rating points-10
s
Sept. 18, 2019, 5:12 p.m.
sanyalitv

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

  • Result:80points,
  • Rating points4
Last comments
M
Sept. 20, 2019, 11:25 a.m.
Mark

вызываю метод get у m_downloader в другом методе и приложение начинает вылетать. В чем ошибка?
M
Sept. 19, 2019, 5:45 a.m.
Mark

А вот как выгрузить файл на сервер по http протоколу? Допустим на regRu. И как получить путь файла, которой отображается в файловом менеджере regRu, чтобы загрузить его.
Sept. 17, 2019, 6:07 a.m.
Misha Lebedev

Кстати интересные темы нашёл тут https://emacsway.github.io/ru/django-framework/#django-models Может что полезного тоже Евгений найдёте
Sept. 17, 2019, 4:50 a.m.
Misha Lebedev

Доброго времени суток. Спасибо за хороший ответ, У меня ситуация така что в галлереи будет несколько миллионов фотографий с фильтрами и тегами , и я опасаюсь за производительност . Это ос…
Sept. 17, 2019, 3:23 a.m.
Evgenij Legotskoj

Добрый день. Да, я тоже читал ту статью в своё время и согласен с тем, что внешние ключи гораздо лучше, чем GenericForeignKey. Выборки в ряде случае работают быстрее. Но лично мне про…
Now discuss on the forum
C
Sept. 21, 2019, 1:58 p.m.
Cobra91151

Здравствуйте! Как вариант могу вам посоветовать QFtp класс, с помощью него можна просматривать, удалять, переименовывать и т.д файлы на сервере через клиентское ПО. Если вас такое интересу…
MS
Sept. 21, 2019, 12:51 p.m.
Mihail Sermjazhko

Так работает import QtQuick 2.7import QtQuick.Window 2.2import QtQuick.Controls 2.0Window { id: demo width: 800 height: 600 visible: true color: "#ff303030" prope…
MS
Sept. 21, 2019, 11:46 a.m.
Mihail Sermjazhko

Говорят через делегат должно работать: ListView{ id:l anchors.fill: parent model: ["data 1","data 2","data 3"] currentIndex : 2 delegate: Text { Rectangle{ …
C
Sept. 21, 2019, 9:08 a.m.
Cobra91151

Здравствуйте! Я хочу подключатся к сетям WiFi Enterprise через свою программу. Настроил Radius Server, поключение к сети через Windows работает. Но при подключении через программу пишет: о…
Sept. 20, 2019, 4:56 a.m.
Pavel K.

Привет , подскажите кто-нибудь , как сделать драг н дроп , не нарушая при этом логику работы зума? import QtQuick 2.6 import QtGraphicalEffects 1.0 Page { id:win property string fi…
EVILEG
About
Services
© EVILEG 2015-2019
Recommend hosting TIMEWEB