当前位置:Gxlcms > 数据库问题 > django 连接mysql 数据库

django 连接mysql 数据库

时间:2021-07-01 10:21:17 帮助过:28人阅读

django.db import models 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, on_delete=models.CASCADE) choice_text = models.CharField(max_length=200) votes = models.IntegerField(default=0)

 

7、修改mysite/settings.py 文件INSTALLED_APPS 添加  ‘polls.apps.PollsConfig‘,

INSTALLED_APPS = [
‘polls.apps.PollsConfig‘,
‘django.contrib.admin‘,
‘django.contrib.auth‘,
‘django.contrib.contenttypes‘,
‘django.contrib.sessions‘,
‘django.contrib.messages‘,
‘django.contrib.staticfiles‘,
]



7、执行命令:python manage.py makemigrations polls

Migrations for ‘polls‘:
  polls/migrations/0001_initial.py:
    - Create model Choice
    - Create model Question
    - Add field question to choice

8、执行命令:python manage.py sqlmigrate polls 0001
技术分享

 9 再执行python manage.py migrate 命令,创建数据库表

技术分享

 

 

django 连接mysql 数据库

标签:项目目录   files   asc   content   foreign   ack   ice   技术分享   tab   

人气教程排行