Alex Sh.
Alex Sh.

Reputation: 225

Django project settings for production and development

In Django I have updated my git with pull from repo. And when I run python3 manage.py collectstatic it throws "myproject" database does not exist. Really I do not have myproject database because in production I have only prod_project database. But, somehow django is trying to load myproject database from base.py rather than loading from prod.py

# base.py
    DATABASES = {                                                                        
            'default': {                                                                     
                'ENGINE': 'django.db.backends.postgresql_psycopg2',                          
                'NAME': 'myproject',                                                       
                'USER': 'admin',                                                            
                'PASSWORD': '*****',
                'ATOMIC_REQUESTS': True,                                                              
            },                                                                               
        }   

# prod.py
    from .base import *                                                                  

    DEBUG = False                                                                        
    TEMPLATE_DEBUG = DEBUG                                                               

    DATABASES = {                                                                        
        'default': {                                                                     
            'ENGINE': 'django.db.backends.postgresql_psycopg2',                          
            'NAME': 'prod_myproject',                                                       
            'USER': 'admin',                                                            
            'PASSWORD': '',                                                              
        },                                                                               
    }                                                                                    

    try:                                                                                 
        from .local import *                                                             
    except ImportError:                                                                  
        pass

# local.py is empty file

my project is in apps/project/prod folder:

/.git
etc/
apps/
static/
myproject/
  settings/
    base.py
    prod.py.
    beta.py
  wsgy.py
manage.py

Upvotes: 1

Views: 2504

Answers (2)

Alex Sh.
Alex Sh.

Reputation: 225

When I did git pull, __init__.py inside the settings was also changed. I did not know about it. The developer who I know advised me to check this file. I discovered that different setting file was set as default. I corrected it. Now it is working.

Upvotes: 0

Beomi
Beomi

Reputation: 1727

If you seperate those 2 setting.py, you should declare which settings.py to use!

You can do this with below(mod_wsgi):

import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'your_proj/settings_location/prod'

this sets django to use specific settings file.

or you can do with this on shell:

python manage.py collectstatic --settings=your_proj/settings_location/prod

this specify the settings file you need.

Ref: https://docs.djangoproject.com/en/1.10/topics/settings/#on-the-server-mod-wsgi

Upvotes: 3

Related Questions