1

I have a working Django 1.6 project using sqlite deployed in Digital Ocean, Ubuntu.

I use Git to update my project on server side. (Git clone and git pull thereafter)

My question is: every time after I update my database locally (e.g. added some new tables), how can I synchronise with the server one? Using git pull results in conflicts that cannot be resolved. I can do it using git fetch --all and git reset --HARD. But it doesn't seem to be the correct way.

Any help is greatly appreciated! Thank you in advance.

1 Answer 1

2

Follow the following steps to push from local and pull to server.

  1. make changes to models.py
  2. Use this cmd to add change to git . > git add models.py
  3. use this cmd to commit > git commit -m "your message"
  4. git push > this will push your local changes to repo.
  5. go to sever now.
  6. run cmd > git status
  7. see if there are any local changes done to models.py file.
  8. you can see those local changes using > git diff models.py
  9. If those changes are already in your repo. use this cmd to discard them > git checkout models.py
  10. Now run cmd which will take your latest changes from server.> git pull

P.S. : Use the same commands for all the changes made to any file into the clone.

South migrations for syncing database:

Initial : 1. python manage.py schemamigration --initial 2. python manage.py migrate --fake

Do any change to database and do following steps: 1. python manage.py schemamigration --auto 2. python manage.py migrate

Do not checkin the migration folder created in app as it will conflict between your local and production clone.

Note: All the history for south migrations are stored in south_migrations table in database.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks for the quick reply. The conflict on the model.py can be resolved as it is editable. The problem lies in the db.sqlite file, which is not editable. I have seen posts saying that git should not be used to synchronise database, but I wonder if there are any ways to do this? I used South to migrate, by the way.
Hey steven, I edited the answer follow the steps to make it work. South is the best way to do that till 1.6 and django 1.7 onwards it is having the native support for migrations. If its solves your problem kindly accept my answer. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.