Search code examples
djangopython-3.xdjango-settings

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

Solution

  • 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.