1. 程式人生 > >django數據模型的創建

django數據模型的創建

創建數據庫 -name ocs https har iter als content href

Django數據模型的創建

1,創建數據庫模型

編輯models.py

from django.db import models

class Article(models.Model):
    title = models.CharField("標題", max_length=30)
    writer = models.CharField("作者", max_length=10)
    content = models.TextField()
    create_date = models.DateField(auto_now_add=True)
    update_date = models.DateField(auto_now=True)
    is_show = models.BooleanField(default=False)

    class Meta:
        db_table = ‘article‘

    def __str__(self):
        return self.title

具體規則見:https://docs.djangoproject.com/en/1.11/topics/db/models/

2,修改setting.py

加上我們的app
技術分享

3,更新數據庫

把新數據遷移工具 (migrations)

$ python manage.py makemigrations --name changed_my_model your_app_label

把新數據遷移到數據庫

$ python manage.py migrate

django數據模型的創建