[Django]-What's best approach to maintain database table field between git branch?

3πŸ‘

βœ…

I understand your situation well and have been in same shoe several times.

Here is what I prefer(/do):

  1. I am in branch bug-fix/surname_degrade
    I changed the user data model [which generated user_migration_005] and then migrated the DB.
    Then my boss came and pointed out that the user is not able to login due to login degrade.

  2. So I have to switch branch and fix that first.

  3. I can rollback the migration[user_migration_005] which I have done few moments back. With something like this python manage.py migrate user_migration_004

  4. Switched branch and started working on hot-fix/login_degrade

  5. When I switch back to my previous task , I can just do migration and proceed.

With this procedure I don’t need to delete my all tables or restore old database or anything like that.

I am a newbie, will be extremely happy to hear your thoughts.

1πŸ‘

The major issue here is that, you database will change everytime You migrate,so either you mantain you database consistency among different branches, or You can do One thing, while using/testing (after declaring all the models)
1) Delete all database tables ( If you have a backup or dummy data )
2) Delete all existing migration files in you branch
3) Create new migrations
4) Migrate to new migrations
The above steps can also be done if the models are re modified, after modification just repeat the steps.

πŸ‘€toddler95

1πŸ‘

Run a different test database in each branch.

When you fork the design, fork the database

Make a clone of the database and migrate that.

πŸ‘€Jasen

0πŸ‘

Make sure when you push to git, you include your migrations, that wait when someone else pulls the branch and does a migrate django knows what changes were made to the database.

πŸ‘€Oh Great One

Leave a comment