码迷,mamicode.com
首页 > 数据库 > 详细

Django使用postgresql数据库

时间:2019-10-21 16:08:06      阅读:321      评论:0      收藏:0      [点我收藏+]

标签:etc   ack   配置文件   postgresq   port   方式   bsp   postgres   size   

1)添加新的数据库用户

 create user <...> with password <...>;

2)创建数据库并指定所属用户

 create database django_test owner <...>;

3)Django数据库配置

注:python环境中需安装psycopg2-binary:pip install psycopg2-binary

 DATABASES = {
 ‘default‘: {
 ‘ENGINE‘: ‘django.db.backends.postgresql_psycopg2‘,
 ‘USER‘: ‘...‘,
 ‘PASSWORD‘: ‘...‘,
 ‘HOST‘: ‘...ip‘,
 ‘PORT‘: ‘...‘,
 ‘NAME‘: ‘...‘
 }
 }

4)修改postgresql配置文件,指定允许远程连接

 # vi /etc/postgresql/10/main/postgresql.conf
 listen_addresses = ‘*‘ # 运行远程连接

5)重启postgresql服务

 systemctl restart postgresql

6)允许任意用户从任意机器上以密码方式访问数据库

 # vi /etc/postgresql/10/main/pg_hba.conf
 host all all 0.0.0.0/0 md5

7)重启postgresql服务

Django使用postgresql数据库

标签:etc   ack   配置文件   postgresq   port   方式   bsp   postgres   size   

原文地址:https://www.cnblogs.com/originalTblog/p/11713871.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!