zoukankan      html  css  js  c++  java
  • model

    一 先用sqlite测试一把:

    1.1 修改配置文件 server/server/setting.py

    # Database
    # https://docs.djangoproject.com/en/dev/ref/settings/#databases
    
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
        }
    }

    1.2 自定义model    /server/blog/models.py

    from django.db import models
    
    # Create your models here.
    class User(models.Model):
        name=models.CharField(max_length=20)

    温馨提示:记得要Application definition  (setting.py)

    INSTALLED_APPS = (                                                                                                          
        'django.contrib.admin',                                                                                                              
        'django.contrib.auth',                                                                                                              
        'django.contrib.contenttypes',                                                                                                          
        'django.contrib.sessions',                                                                                                            
        'django.contrib.messages',                                                                                     
        'django.contrib.staticfiles',                                                                                                               
        'blog',                                                                                                                                 
    )   

     

    1.3   检查model 是否合法。

    If you’re interested, also run the following commands:

    Looking at the output of those commands can help you understand what’s actually happening under the hood.

     1.4  创建数据库

    python manage.py syncdb



    用mysql修改下数据库就可以了。

    修改配置文件 server/server/setting.py
    # Database
    # https://docs.djangoproject.com/en/dev/ref/settings/#databases
    
    DATABASES = {
        'sqlite': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
        },
        'default':{
            'ENGINE': 'django.db.backends.mysql',
            'NAME'  : 'pytest',
            'USER'  : 'root',
            'PASSWORD'  :   '1111',
        },
    }





    用MYSQL数据库实现:








  • 相关阅读:
    mysql参数优化
    看见的一个mysql面试题
    面向对象的继承
    面向对象的权限修饰符
    php实现无限极分类
    php的冒泡排序
    frame框架的跳转
    thinkphp中open路径问题
    mysql触发器
    mysql事务
  • 原文地址:https://www.cnblogs.com/canbefree/p/3945687.html
Copyright © 2011-2022 走看看