How to set up a PostgreSQL database in Django

后端 未结 11 1193
滥情空心
滥情空心 2020-11-29 15:28

I\'m new to Python and Django.

I\'m configuring a Django project using a PostgreSQL database engine backend, But I\'m getting errors on each database operation. For

11条回答
  •  鱼传尺愫
    2020-11-29 15:45

    I was having the same Issue on Mac.

    The solution was to use only PIP to install everything, and touch some things.

    First install PIP from: https://pip.pypa.io/en/latest/

    Then you want to make sure if path to pg_config is in your PATH (echo $PATH), if not you can edit your bash_profile:

    vi /Users//.bash_profile
    

    and add this line:

    export PATH=$PATH:/path/to/pg_config/bin
    

    If you don't know where pg_config is you can use the "locate" tool, but be sure your locate.db is up to date (i was using an old locate.db and using paths that does not exists).

    sudo /usr/libexec/locate.updatedb
    locate pg_config
    

    Then install Django (if needed) and psycopg2.

    sudo pip install Django
    sudo pip install psycopg2
    

    And then in settings.py (localhost:defaultport)

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
            'NAME': 'dbname',
            'USER': 'postgres',
            'PASSWORD': 'postgres',
            'HOST': '',
            'PORT': '',
        }
    }
    

    Greets!

提交回复
热议问题