python安裝配置django--使用數據庫

python安裝配置django–使用數據庫

第一步:在models.py 裏面創建表格

from django.db import models


# Create your models here.
class User(models.Model):
    # 創建主鍵 創建username varchar
    uid = models.AutoField(primary_key=True)
    username = models.CharField(max_length=32)
    password = models.CharField(max_length=32)
    sex = models.IntegerField(max_length=1)
    phone = models.CharField(max_length=11)
    # decimal(7,2)
    price = models.DecimalField(max_digits=7, decimal_places=2)
    # 創建用戶的日期
    # create_date = models.DateTimeField(auto_now_add=True)
    create_date = models.DateField(auto_now_add=True)  # 使用auto_now每次都會自動更新
    last_time = models.DateTimeField(auto_now=True)
    head_img = models.ImageField(upload_to='upload/')

第二步:使用數據庫

三步走數據庫搞起
1.pip install Pillow
2.python manage.py makemigrations pen  # 遷移到pen目
3.python manage.py migrate pen
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章