• 修改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

相关文章:

  • 2022-12-23
  • 2021-11-30
  • 2021-09-01
  • 2021-11-17
  • 2021-11-28
  • 2021-12-20
  • 2022-12-23
  • 2021-11-19
猜你喜欢
  • 2021-09-26
  • 2021-06-23
  • 2021-08-25
  • 2021-08-20
  • 2021-08-31
  • 2021-10-13
相关资源
相似解决方案