简体   繁体   English

无法将Django应用连接到外部PostgreSQL数据库

[英]Unable to connect Django app to an external PostgreSQL database

Short Description 简短的介绍
I am having a number of issues trying to connect a Django app (currently setup as SQLite3) to a newly created PostgreSQL on my Ubuntu Server. 尝试将Django应用程序(当前设置为SQLite3)连接到Ubuntu服务器上新创建的PostgreSQL时遇到很多问题。

The Question(s) 问题
Can anyone share their success in doing this? 谁能分享他们在此方面的成功? Is there a good step-by-step tutorial on doing this? 有一个很好的分步教程吗? Or at least useful pointers on how to debug this? 或者至少是关于如何调试的有用指针?

Steps So Far (Background information) 到目前为止的步骤(背景信息)
1) I have installed PostgreSQL on my Ubuntu Server following this tutorial. 1)按照教程,我已经在Ubuntu服务器上安装了PostgreSQL。 Note that this produced Zero errors. 请注意,这产生了零错误。
2) I configured my Django settings.py as seen below 2)我如下所示配置了Django settings.py

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.postgresql', 
    'NAME': 'mytestdb',                   
    'USER': 'mux_user',                    
    'PASSWORD': 'mux',                  
    'HOST': '192.168.1.111',                      
    'PORT': '',                  
    }
}

3) Ran Django's 'syncdb'. 3)运行 Django的'syncdb'。 This generated the following error. 这产生了以下错误。

django.core.exceptions.ImproperlyConfigured: Error loading psycopg module: No module named psycopg django.core.exceptions.ImproperlyConfigured:加载psycopg模块时出错:没有名为psycopg的模块

4) Attempted to install psycopg with PIP, easy_install, and with the setup.py. 4)尝试通过PIP,easy_install和setup.py安装psycopg。 All had the same failure of not being able to find the pg_config. 所有人都有同样的失败,无法找到pg_config。

5) Google told me that I needed to install libpq-dev and python-dev in-order to compile the psycopg package. 5) Google告诉我,我需要依次安装libpq-dev和python-dev才能编译psycopg软件包。 This is where I have lost most of my confidence in understanding what I am doing. 在这里,我失去了对自己正在做的事情的大部分信心。 I understand that these 2 packages are to allow me to compile python source, but is it really necessary to do this? 我知道这两个软件包是为了允许我编译python源,但是这样做真的有必要吗?

System Information 系统信息
Client: 客户:
OS: OS X Snow Leopard-10.6.6 作业系统:OS X Snow Leopard-10.6.6
Django: Version 1.2.5 Django:版本1.2.5
Python: 2.7 (running virtualenv) Python:2.7(运行virtualenv)

Soon to be client 即将成为客户
OS: Windows XP / 7 作业系统:Windows XP / 7
Running an bundled executable of the python environment above 运行上面的python环境的捆绑可执行文件

Server: 服务器:
OS: Ubuntu 10.10 (server, no gui) 操作系统:Ubuntu 10.10(server,no gui)
PostgreSQL: 8.4 (that's what apt-get install downloaded) PostgreSQL:8.4(这是apt-get install下载的)

Update 更新资料
I did find in the documentation where it talks about needing to install psycopg. 我确实在文档中找到有关需要安装psycopg的内容。 I suppose the question moves from do I really need this, to what is the best way to install psycopg on my clients. 我想问题从我真的需要这个,到在我的客户端上安装psycopg的最佳方法是什么。

Update 5-13-2011: 9:20AM 2011年5月13日更新:上午9:20
After speaking with a colleague, I believe this SO question addresses most of my issues 与同事交谈后,我相信这个 SO问题可以解决我的大部分问题

I'm no Python guy but you do need the PostgreSQL libraries installed as the Python interface to PostgreSQL (psycopg) is just a Python layer on top of the PostgreSQL C libraries. 我不是Python专家,但您确实需要安装PostgreSQL库,因为PostgreSQL的Python接口(psycopg)只是PostgreSQL C库之上的Python层。 So, no PostgreSQL development libraries means there's nothing to wrap in Python and no way to talk to PostgreSQL from Python. 因此,没有PostgreSQL开发库意味着没有任何东西可以用Python包装,也没有从Python与PostgreSQL对话的方法。

You need to put your pg_config into your path, first locate this file on your machine, then run something similar to: 您需要将pg_config放入路径中,首先在计算机上找到此文件,然后运行类似于以下内容的文件:

    export PATH=$PATH:/opt/local/lib/postgresql90/bin
    pip install psycopg2

If you do not have postgres installed on your client machine, then you should be able to install with macports: 如果您的客户端计算机上未安装postgres,则应该可以使用macports进行安装:

    sudo port install postgresql90

The issues I ran into were centered around using a 32bit install of Python (required by wxPython 2.8 on Snow Leopard). 我遇到的问题集中在使用32位安装的Python(Snow Leopard上的wxPython 2.8要求)上。 Please see my answer on this SO Question . 请参阅我对此问题的回答

@mu is too short: Thanks for the help. @mu太短:感谢您的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法使用 Django 上的 SSL 连接到 PostgreSQL - Unable to connect to PostgreSQL with SSL on Django Django应用程序与外部API连接 - Django app connect with external API 无法使用Django连接到本地Postgresql服务器 - Unable to connect to local Postgresql server using django 如何连接我现有的外部 PostgreSQL 数据库以自动为 Django Rest 框架创建我的 Models.py? - How can I connect my existing external PostgreSQL Database to automatically create my Models.py for a Django Rest Framework? 适用于 Linux 2 的 Windows 子系统:Ubuntu,连接到外部 PostgreSQL 数据库 - Windows Subsystem for Linux 2: Ubuntu, connect to external PostgreSQL database 在pythonanywhere上将Django Web应用程序数据库连接到Postgresql - Connecting Django web app database to postgresql on Pythonanywhere 关于如何在 Django 应用程序中处理 PostgreSQL 数据库的建议? - Advice on how to handle PostgreSQL database in Django app? 在 Heroku 上的 Django 应用程序中使用外部数据库 - Use an external database in Django app on Heroku Django 不使用 docker 连接到 postgresql 数据库 - Django doesn't connect to postgresql database using docker 如何将我的 postgresql 数据库与我的 django 项目连接起来? - How to connect my postgresql database with my django project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM