在Django上设置postgresql和运行代码

来源:互联网 发布:下电影的网站 知乎 编辑:程序博客网 时间:2024/06/18 06:56

创建postgresql数据库

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

在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_logCreating table auth_permissionCreating table auth_group_permissionsCreating table auth_groupCreating table auth_user_groupsCreating table auth_user_user_permissionsCreating table auth_userCreating table django_content_typeCreating table django_sessionCreating table jiandu_gov_pol_air_resultCreating table jiandu_gov_pol_water_resultCreating table jiandu_gov_pol_mental_resultCreating table jiandu_gov_pol_danger_resultYou just installed Django's auth system, which means you don't have any superusers defined.Would you like to create one now? (yes/no): yesUsername (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#测试运行代码
0 0
原创粉丝点击