Connection to Django default failed

1.4k views Asked by At

So i'm using Pycharm and have installed the Django framework and Postgres. When I initially setup the default Django DB to point to the Postgres database everything works fine.

The problem occurs if I make any changes to a table, meaning the table structure, then try to synchronize the database in Pycharm I'm getting an error message saying "Django default - Connection to Django default failed:"

Here is my setup: OSX Maverick Postgres 9.3 Django 1.5 Pycharm 3 Python 3.3

Any assistance someone can give is greatly appreciated!

1

There are 1 answers

0
lukeaus On BEST ANSWER

It looks like Django can't connect to Postgres. You might just need to tweak your settings.py file to make sure you have the correct postgres DB info in there.

In any event here is a more complete guide:

To get django working with Pycharm

  1. Make sure you have followed how to install django correctly https://docs.djangoproject.com/en/dev/topics/install/

2.go to the project drop down box and click edit configuration then make sure host = 127.0.0.1 port = 8000

make sure it is using python 3.x.x as the interpreter rather than python 2.x

  1. In Pycharm go to Preferences —> Django make sure it is enabled and then:

    • Django Project Root connects to the root of your project (usually where manage.py is)
    • Settings points to your settings.py file inside your project
    • Manage script points to manage.py
  2. make sure you have installed psycopg2 if you are using python3 that means using pip3 not pip (pip is for python 2.x) pip3 install psycopg2

  3. Edit your settings.py file as below

DATABASES = {

    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'polls',
        'USER': 'lms',
        'PASSWORD': '',
        'HOST': '',  #note an empty string means localhost
        'PORT': '5432',
        'OPTIONS': {
            'autocommit': True,
        }
    }

}

note the default postgres port is 5432 - if it is not connecting using that check this post: postgresql port confusion 5433 or 5432?

this may also be useful: http://marcinkubala.wordpress.com/2013/11/11/postgresql-on-os-x-mavericks/