django 1.7 migrations — how do I clear all migrations and start over from scratch?

后端 未结 2 1434
暗喜
暗喜 2021-01-30 03:56

So I\'m rapidly iterating on a django app at the moment and I\'m constantly adjusting models.py. Over the course of a day or two of programming and testing I generate a couple

2条回答
  •  日久生厌
    2021-01-30 04:58

    I just wanted to put all the steps into a command format:

    NOTE: The commands below are pretty destructive, it is a means to start from scratch as the OP asked.

    After a comment from mikeb I thought to add this line:

    PRE - CHECK WHAT FILES YOU WOULD DELETE

    find . -path "*migrations*" -name "*.py" -not -path "*__init__*"

    Then, adjust the command in step 1 to one that works for your dev environment.

    1. remove all the migrations from all the apps:
    find . -path "*migrations*" -name "*.py" -not -path "*__init__*" -exec rm {} \; # make sure to be in your projects path
    1. recreate the whole database:
    sudo -u postgres bash -c "psql -c \"DROP DATABASE rootedin;\""
    sudo -u postgres bash -c "psql -c \"CREATE DATABASE rootedin;\""
    sudo -u postgres bash -c "psql -c \"GRANT ALL PRIVILEGES ON DATABASE rootedin to vagrant;\"" # vagrant is my current user
    1. get your db up to date:
    python3 manage.py makemigrations
    python3 manage.py migrate
    

提交回复
热议问题