Git merging conflicts with our database file (several developers)

My friend and I are developing an application for Django and using git.

While working, we create fake accounts on our website, log in, upload content to the database, etc. For testing purposes. Each time we merge branches, we get merge conflicts in our database file . The database file is in the repository, and since we are testing separately, local copies of the file evolve differently.

How to prevent tracking of a database file so that each of us can store our local copies?

Thanks to the following, we were able to avoid using the local path:

## settings.py from os.path import dirname, join PROJECT_DIR = dirname(__file__) DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': join(PROJECT_DIR, 'foo.db'), 'USER': '', 'PASSWORD': '', 'HOST': '', 'PORT': '', } } 

What would be ideal is something like:

 ## settings.py from os.path import dirname, join PROJECT_DIR = dirname(__file__) DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': join('../../../', PROJECT_DIR, 'foo.db'), # this path is outside the repository (ie, 'Users/sgarza62/foo.db') 'USER': '', 'PASSWORD': '', 'HOST': '', 'PORT': '', } } 

How can we prevent the transfer of files in our database?

+7
source share
4 answers

Add the database file to .gitignore . You can then save it at your current location, but it will not be versioned.

+12
source

First, you will want to remove the database file from the git repository.

 git rm <database_file> 

To prevent the file from being added to the repository, create a file named ".gitignore" inside your repository repository, add the database file to .gitignore and add .gitignore to your repository. ( Documentation )

To prevent conflicts with settings.py options, I also add settings.py to .gitignore. Then I create a file called "settings.production.py" that contains all the settings for the production server and adds it to the repository. In my local check, I just copy this file to settings.py and change the variables as needed. On my production server, I make a symbolic link to settings.production.py.

 ln -s settings.production.py settings.py 

Attention:

  • If your repository is publicly accessible, it should never store secret keys, passwords, certificates, etc. You do not want others to have access to these files.
  • You must also ensure that your web server is not serving the .git folders. A hacker could access the source code if http://example.com/.git is available.
+5
source

When you are working on projects with another ppl repo exchange, you should do local_settings.py and save all local settings there :) Then in settings.py just add from local_settings import * . And add the local_settings.py file and the database to the .gitignore file.

In the example, if your file name is database.db , then in the directory with this file create a file named .gitignore and write database.db or *.db in it to ignore all db files.

+1
source

This is a common problem. I would recommend not checking in the database and loading and saving data if necessary. ( https://docs.djangoproject.com/en/dev/howto/initial-data/ )

Create the test_data directory and run the following commands to export your database to the json agnostic database file:. /manage.py dumpdata> test_data / test_file_1.json

Check the file in the source code. At any time, if you want to restore the database for this point, simply run:. /manage.py loaddata test_data / test_file_1.json

This also has the advantage of being used for unit tests (see Downloading fixtures in django unit tests )

 from django.test import TestCase class MyTestCase(TestCase): fixtures = ['/myapp/fixtures/dump.json',] 
+1
source

All Articles