Search code examples
pythondjangodjango-fixtures

Is there a way to prevent fixtures from loading according the environment?


I use en .env file per environement to set settings variables that must be different according the environment. An exemple would be:

in settings.py file: DEBUG = (os.environ['DJANGO_DEBUG'] in ['True', 'true'])

in .env file of DEV environment: DJANGO_DEBUG=True

I'd like when I run syncdb in production environment that the fixtures do not load. I read documentation but didn't find any settings var related to fixtures.

How would you do? (Currently, I'm just not uploading the fixtures files on github, dirty!) Note that I'm using Django 1.6.

Thanks.


Solution

  • There's a settings variable you can use called FIXTURE_DIRS. In Django 1.6, this is a list of the directories that will be searched for fixtures, in addition to any directory called 'fixtures' in the root of the app. FIXTURE_DIRS is an empty tuple by default.

    You can't prevent the 'fixtures' directory being searched, so make sure you don't have a directory by that name. Instead, create a directory for your fixtures and give it any other name. I'll call mine 'my-fixtures' in the example below.

    Now since you've already checked whether or not DEBUG is true, you can add two lines to the end of settings.py:

    if DEBUG:
        FIXTURE_DIRS = ['my-fixtures']