从头开始创建django项目和链接postgreSQL

来源:互联网 发布:mac打开文件夹很慢 编辑:程序博客网 时间:2024/04/30 22:31

创建数据库

ubuntuq@ubuntuq-HP-Compaq-6910p-RH241AV:~/下载/wuran$ su postgres密码: postgres@ubuntuq-HP-Compaq-6910p-RH241AV:/home/ubuntuq/下载/wuran$ psqlpsql (9.3.11)Type "help" for help.postgres=# \lpostgres=# CREATE DATABASE webdatabase owner geeklee;CREATE DATABASE

创建django项目

ubuntuq@ubuntuq-HP-Compaq-6910p-RH241AV:~/临时文件夹/mysite$ django-admin.py startproject mysitesubuntuq@ubuntuq-HP-Compaq-6910p-RH241AV:~/临时文件夹/mysite$

在你的Django中给创建的数据库加上配置

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

迁移数据库,运行代码

ubuntuq@ubuntuq-HP-Compaq-6910p-RH241AV:~/临时文件夹/mysite$ cd mysitesubuntuq@ubuntuq-HP-Compaq-6910p-RH241AV:~/临时文件夹/mysite/mysites$ 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_sessionYou 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): Superuser created successfully.Installing custom SQL ...Installing indexes ...Installed 0 object(s) from 0 fixture(s)ubuntuq@ubuntuq-HP-Compaq-6910p-RH241AV:~/临时文件夹/mysite/mysites$ python manage.py runserver#运行代码Validating models...0 errors foundOctober 10, 2016 - 13:37:42Django version 1.6.6, using settings 'mysites.settings'Starting development server at http://127.0.0.1:8000/Quit the server with CONTROL-C.[10/Oct/2016 13:37:46] "GET / HTTP/1.1" 200 1757

网站运行效果
这里写图片描述

Django应用数据库从MySQL到PostgreSql的迁移
在Django中使用PostgreSQL数据库

0 0
原创粉丝点击