3

I have a Django app that was setup for Sqlite and working fine. Now I want to switch to Postgres. I installed this requirement:

psycopg2==2.6

And I changed my settings.py to:

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

BASE_URL = "localhost:8000"


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '#############################################'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'raven.contrib.django.raven_compat',
    'django_extensions',
    'crispy_forms',
    'compressor',
    'rest_framework',

    'accounts',
    'lists',
)

CRISPY_TEMPLATE_PACK = "bootstrap3"

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'mysite.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'lists.context_processors.extra_context',
            ],
        },
    },
]

WSGI_APPLICATION = 'mysite.wsgi.application'

DATABASES = {                                                                    
    'default': {                                                                 
        'ENGINE': 'django.db.backends.postgresql_psycopg2',                      
        'NAME': 'my_database_name',                                                   
        'USER': 'my_database_user',                                                   
        'PASSWORD': 'my_database_password',                                      
        'HOST': '127.0.0.1',                                                     
        'PORT': '5432',                                                          
    }                                                                            
} 

# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/

STATICFILES_DIRS = (
    'bower_components',
    'less',
    'css',
    'scripts',
)

STATICFILES_FINDERS = (
    "django.contrib.staticfiles.finders.FileSystemFinder",
    "django.contrib.staticfiles.finders.AppDirectoriesFinder",
    "compressor.finders.CompressorFinder",
)

STATIC_URL = '/static/'

STATIC_ROOT = BASE_DIR + '/static/'

COMPRESS_PRECOMPILERS = (
    ('text/less', 'lessc {infile} {outfile}'),
)

AUTH_USER_MODEL = "accounts.Account"

The problem is when I run either:

python manage.py syncdb

or

python manage.py migrate

It creates a new Sqlite database! I'm on my local server, localhost:8000. Postgres is running fine, and I've created the database appropriately in postgres. Why could this be happening and how can I get my Postgres database setup?

EDIT:

When I print settings.DATABASES from the shell, it still shows:

{'default': {'ATOMIC_REQUESTS': False,
             'AUTOCOMMIT': True,
             'CONN_MAX_AGE': 0,
             'ENGINE': 'django.db.backends.sqlite3',
             'HOST': '',
             'NAME': '/mysite/db.sqlite3',
             'OPTIONS': {},
             'PASSWORD': '',
             'PORT': '',
             'TEST': {'CHARSET': None,
                      'COLLATION': None,
                      'MIRROR': None,
                      'NAME': None},
             'TIME_ZONE': 'UTC',
             'USER': ''}}
YPCrumble
  • 26,610
  • 23
  • 107
  • 172
  • Can you post your whole `settings.py` (make sure you blank out passwords and hosts)? –  May 12 '15 at 01:25
  • @LegoStormtroopr there you go, thanks for taking a look! – YPCrumble May 12 '15 at 01:39
  • did you restart apache? settings.py is most likely cached so in order for you changes to be taken into account, you might need to restart your server. – Julien Grégoire May 12 '15 at 01:47
  • @JulienGrégoire this is on local, edited my post to reflect that. Is there a need to do this on local? I'm using `python manage.py runserver` to run the `localhost:8000` server. – YPCrumble May 12 '15 at 01:53
  • If you print `settings.DATABASES` inside `./manage.py shell`, is the output same as your settings.py? And if you search text "sqlite" (case insensitive) in all project files, any occurrence? – ZZY May 12 '15 at 02:03
  • @ZZY it does not! See my edit above. Any sense as to why? – YPCrumble May 12 '15 at 02:07
  • If "sqlite" text doesn't appear anywhere in your codes, maybe you can try to remove settings.pyc – ZZY May 12 '15 at 02:19
  • @ZZY you got me there! I actually did have a `.pyc` file left behind on accident with `sqlite` in it. I removed that and everything worked as expected. – YPCrumble May 12 '15 at 02:24
  • Actually the ".pyc" files should not cause this error. If ".pyc" files' timestamp don't match according ".py" files' last modified time, Python will re-compile pyc files. I don't know why it happened in your case. – ZZY May 12 '15 at 02:34
  • @ZZY Thanks!!! solved my issue – Reck Jun 14 '16 at 13:06

0 Answers0