python - 同步数据库时我应该使用什么密码?

标签 python django postgresql passwords syncdb

嗨,我对 django 很陌生,刚刚学习了 python。我正在努力把一切都安排好。所以现在道歉!

我安装了 django 和 python(Windows 7)。到目前为止,教程中的所有内容(在某种程度上)都有效。现在尝试同步我的第一个数据库,如教程帖子中所示。我在 myadmin III 中创建了一个名为 posts 的文件,我的setting.py 文件看起来像..

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': os.path.join(BASE_DIR, 'C:/Program Files/PostgreSQL/9.3/data/base/polls.db'),
        'PASSWORD': '',

但是我收到此错误(以及其他错误)

conn = _connect(dsn, connection_factory=connection_factory, async=async)
django.db.utils.OperationalError: fe_sendauth: no password supplied

数据库似乎没有设置密码,postgresql 中也没有服务器连接。所以不知道我需要做什么?

我应该使用什么密码?

非常感谢!

最佳答案

我假设在阅读本教程时,您正在使用开发服务器 (manage.py runserver) 在本地计算机上工作。在这种情况下,我建议仅使用 sql lite,因为您似乎正在尝试在设置中执行此操作。

以下内容应该可以很好地让您的syncdb正常工作。

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3', 
        'NAME': os.path.join(BASE_DIR, 'polls.db'), #name field represents filepath for sqlite
    }
}

如果您想使用 postgres 的本地实例,则需要在 name 参数中指定数据库名称。它看起来更像

DATABASES = {
  'default': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'NAME': 'polls', # name of psql db on your running database server
    'HOST': 'localhost', #assuming psql is running locally
    'PORT': 5432,
    'USER': 'username', #admin username that you set up with no password
    'PASSWORD': '', 
  }
}

关于python - 同步数据库时我应该使用什么密码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19444175/

相关文章:

php - 用于将 zip 文件加载到数据库中的 Postgres 复制命令

postgresql - Postgresql 函数中的 "$$"是什么意思?

python - 在 Python 中尝试直到没有错误

python - 如何将模型操作传递给 Tkinter MVC 中的查看按钮?

python - 使用嵌套的可写序列化程序上传 django rest 框架文件

django - myproject 的 wsgi.py 无法读取 settings.py

python - 在 ubuntu 上安装 paramik/Crypto

python - cv2.VideoWriter 的输出不正确。更快

python - DRF的嵌套关系: serializer output OrderedDict with Tuple

java - PostgreSQL, hibernate : Default increase sequence length by 1