python installation configuration django--use database

python install configure django – use database

Step 1: Create a table in 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/')

Step 2: Using the Database

三步走数据库搞起
1.pip install Pillow
2.python manage.py makemigrations pen  # 迁移到pen目
3.python manage.py migrate pen

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324823499&siteId=291194637