git merge conflicts with our database file (multiple developers)

A buddy and I are developing a Django app, and are using git (GitHub).

As we work, we make fake accounts on our site, login, and upload content to the database, etc..for testing purposes. Here’s the problem: every time we merge branches on GitHub, we get merge conflicts with our database file. This of course, is because our database file is in the repository, and since we’re testing separately, the local copies of the file develop differently.

  • Git Merge with ignored migrations files
  • Django Jenkins raises WebDriverException when processed to Selenium server
  • Develping with Django, Git, and Cloud Server
  • Same Django project different GIT repositories
  • Having trouble setting up dev server for Django and website
  • Python / pip, how do I install a specific version of a git repository from github (what is the correct url)?
  • What I would like to do is have the database file be outside the repository. This way, we can merge, and always keep our own copy of the database running, independent of the other guy’s local copy.

    However, our settings.py file has to be the same, so we can’t specify a local path (ie, ‘Users/sgarza62/Desktop’ or ‘Users/rada/Desktop). This would be ideal, but the settings.py file is a shared file, so it must be the same in both copies of the repository.

    With the following, we’ve been able to avoid using a 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 keep our database files outside of the repository?

  • What are the underlying git merge processes within the staging area?
  • JetBrains (IntelliJ, PhpStorm, WebStorm …) private git repository with SSH key
  • How to get a list of directories deleted in my git repository?
  • Start gitk from git gui command line
  • Can git ever send your code to a repo that isn't yours?
  • git tells me that I Merge conflict, but also tells me that no files need merging
  • 4 Solutions collect form web for “git merge conflicts with our database file (multiple developers)”

    Add your database file to .gitignore. Then you can keep it in its current location, but it will not be under version control.

    First off, you’ll want to remove the database file from your git repository.

    git rm <database_file>
    

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

    To prevent conflicts with settings.py, I also add settings.py to .gitignore. I then create a file called “settings.production.py”, which contains all of the settings for the production server, and add it to the repository. On my local checkout, I simply copy this file into settings.py and modify variables as needed. On my production server, I make a symlink to settings.production.py.

    ln -s settings.production.py settings.py
    

    WARNING:

    1. If your repository is public, it should never store secret keys, passwords, certificates, etc. You don’t want others to have access to these files.
    2. You should also verify that your web server does not serve “.git” folders. A hacker could gain access to your source code if http://example.com/.git is accessible.

    When you work on projects with other ppl sharing repo, you have to make local_settings.py and keep there all local settings 🙂 Then in settings.py just add from local_settings import *.
    And add local_settings.py and database file to .gitignore file.

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

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

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

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

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

    from django.test import TestCase
    class MyTestCase(TestCase):
        fixtures = ['/myapp/fixtures/dump.json',]
    
    Git Baby is a git and github fan, let's start git clone.