在Django上设置postgresql和运行代码

创建postgresql数据库

ubuntuq@ubuntuq-HP-Compaq-6910p-RH241AV:~$ su postgres
密码: 
postgres@ubuntuq-HP-Compaq-6910p-RH241AV:/home/ubuntuq$ psql
psql (9.3.11)
Type "help" for help.
postgres=# CREATE DATABASE pol_gov_mon owner deploy;
CREATE DATABASE
postgres=#

在django中设置postgresql数据库信息

把PostgreSQL中的数据库信息放在django设置中
settings.py部分代码如下:

DATABASES = {
    'default': {
         'ENGINE': 'django.db.backends.postgresql_psycopg2',
         'NAME': 'pol_gov_mon',
         'USER': 'deploy',
         'PASSWORD': 'XXX',
         'HOST': '127.0.0.1',
         'PORT': '5432',
         #'CONN_MAX_AGE': 5,
     }
}

在django中迁移数据库和运行代码

ubuntuq@ubuntuq-HP-Compaq-6910p-RH241AV:~/下载/wuran$ python manage.py syncdb
#迁移数据库
Creating tables ...
Creating table django_admin_log
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table jiandu_gov_pol_air_result
Creating table jiandu_gov_pol_water_result
Creating table jiandu_gov_pol_mental_result
Creating table jiandu_gov_pol_danger_result

You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (leave blank to use 'ubuntuq'): #可为空
Email address: #可为空
Password: 
Password (again): 
Error: Blank passwords aren't allowed.
Password: #填入密码
Password (again):#填入密码 
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
ubuntuq@ubuntuq-HP-Compaq-6910p-RH241AV:~/下载/wuran$ python manage.py xinjiang getall
#测试运行代码

你可能感兴趣的:(数据库)