Django: How to completely uninstall a Django app?

前端 未结 5 492
星月不相逢
星月不相逢 2020-12-12 10:35

What is the procedure for completely uninstalling a Django app, complete with database removal?

5条回答
  •  粉色の甜心
    2020-12-12 11:33

    In my context the projects exists several times: I have a development system, some team mates have a development system, there is a staging system for the customer and a production system. This means I don't want to execute sql commands by hand. I want it to be automated.

    Goal: Remove the app and all database tables.

    Step 1: empty the app, but leave it installed

    remove all files from the app, except the folder "migrations"

    Execute this command: manage.py makemigrations -n drop_all_tables my_app_to_remove

    The directory looks now like this:

    my_app_to_remove/
    my_app_to_remove/__init__.py
    my_app_to_remove/migrations
    my_app_to_remove/migrations/0001_initial.py
    my_app_to_remove/migrations/....
    my_app_to_remove/migrations/0030_drop_all_tables.py
    my_app_to_remove/migrations/__init__.py
    

    Leave my_app_to_remove in the file "settings.py".

    Step 2: Deploy the changes

    Update all projects. Tell the team mates to update their project and to run the migrations.

    Step 3: remove "my_app_to_remove" from settings.py

    Now remove "my_app_to_remove" from settings.py and deploy again.

提交回复
热议问题