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

猜你喜欢

转载自blog.csdn.net/Markwangyu/article/details/80062873