Search code examples
pythondjangopostgresqldjango-modelsdjango-migrations

django migration - re-creating the database


I am running python 2.7 and django 1.8.

I have this exact issue.

The answer, posted as a comment is: What I did is completely remake the db, erase the migration history and folders.

I am very uncertain about deleting and creating the database.

I am running a PostgreSQL database. If I drop/delete the database and then run the migrations, will the database be rebuilt from the migrations? I don't want to delete the database and then be stuck in a worse situation.


Solution

  • Here is what I did to correct this issue:

    First, make a script of the data, so that when the database is destroyed and re-created, the data can be easily re-created.

    Next run the following script to reset the database (this will delete all the db data and remove the db tables).

    Then run the following script to recreate the db:

    python manage.py reset_db

    Then, run the following script to re-create the db:

    python manage.py migrate

    Next, run the script to create the database data.

    Finially, run the following script to start the server:

    python manage.py runserver

    That is it.

    I hope that this helps some one out there.