Sqlite database conflict when merging into git

Asked

Viewed 51 times

0

I’m working with someone else on a Django project and she owns the main repository. I have a Fork from this repository and want to update it with the original.

I created the upstream: git remote add upstream <endereço-do-repositorio.git> Afterward: git fetch upstream Until then it went well, but in time to merge (git merge upstream/master) submitted the error:

warning: Cannot merge binary files: db.sqlite3 (HEAD vs. upstream/master)
Unlink of file 'db.sqlite3' failed. Should I try again? (y/n) n
error: failed to create path 'db.sqlite3': perhaps a D/F conflict?
Auto-merging db.sqlite3
CONFLICT (content): Merge conflict in db.sqlite3
Automatic merge failed; fix conflicts and then commit the result.

I understood that the problem is the divergences of my bank with the other person, but how can we solve to be able to work as a team without causing interference in the main project? Thank you.

  • The database needs to be versioned with Git?

  • You have to add the extension . sqlite3 the gitignore file, you should not upload database to git

1 answer

1


The Git is trying to versioning the database file, a binary, and then generating a conflict that it cannot solve easily (and much less securely) and for this, and other reasons, should not be versioned in the project. And in the case of Django history of database changes will already be stored with the files models.py as well as in migrations.

Solution to your problem, remove the db.sqlite3 repository

git rm --cached db.sqlite3

The --cached says to the Git only remove from the versioning system and do not delete the file itself.

It is also recommended to add the .gitignore:

echo 'db.sqlite3' >> .gitignore

So no one puts it back in the project and then sends the changes:

git add .gitignore
git commit -m "Remove o 'db.slite3' do repositório"

And here is a recommendation, the staff will need to rename the db.sqlite3 before updating or receiving something like the message:

error: The following untracked working tree files would be overwritten by checkout:
    db.sqlite3
Please move or remove them before you switch branches.

But then rename the file, update the repository and return the name to db.sqlite3.

And having the need to make a backup of the data of Django take a look at the "dumpdata" and "loaddata" commands of manage.py.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.