zoukankan      html  css  js  c++  java
  • Django-数据模型

    • 修改model.py文件
    • from django.db import models
      
      # Create your models here.
      
      class Question(models.Model):
          question_text = models.CharField(max_length=200)
          pub_date = models.DateTimeField('date published')
      
      
      class Choice(models.Model):
          question = models.ForeignKey(Question)
          choice_text = models.CharField(max_length=200)
          votes = models.IntegerField(default=0)
    • 生成合并数据脚本:python manage.py makemigrations
    • ➜  mysite  python manage.py makemigrations polls
      Migrations for 'polls':
        0001_initial.py:
          - Create model Choice
          - Create model Question
          - Add field question to choice
    • 应用改变到数据库中:python manage.py migrate
    • ➜  mysite  python manage.py migrate
      Operations to perform:
        Synchronize unmigrated apps: staticfiles, messages
        Apply all migrations: admin, contenttypes, polls, auth, sessions
      Synchronizing apps without migrations:
        Creating tables...
          Running deferred SQL...
        Installing custom SQL...
      Running migrations:
        Rendering model states... DONE
        Applying polls.0001_initial... OK
  • 相关阅读:
    MongoDB的安装与简单使用
    [SCOI2008]天平
    [ZJOI2008]树的统计
    [HEOI2015]兔子与樱花
    [HAOI2006]l旅行
    [ZJOI2008]泡泡堂BNB
    [ZJOI2007]时态同步
    [SCOI2005]栅栏
    [SCOI2008]着色方案
    [SCOI2005]互不侵犯King
  • 原文地址:https://www.cnblogs.com/s380774061/p/5006635.html
Copyright © 2011-2022 走看看