官方文档:https://docs.djangoproject.com/zh-hans/3.2/ref/models/fields/
blank,控制Django表单是否为空
null,控制MySQL字段值是否为空
# models.py
from django.db import models
class Book(models.Model):
title = models.CharField(max_length=50, default="", verbose_name="书名")
price = models.DecimalField(max_digits=7, decimal_places=2, verbose_name="价格")
info = models.CharField(max_length=100, default="", verbose_name="描述")
market_price = models.CharField(max_length=50, default="", verbose_name="市场价")
class Meta:
db_table = "book"
C:\Users\520\mysite>python manage.py makemigrations
Migrations for 'myapp':
myapp\migrations\0003_alter_book_table.py
- Rename table for book to book
C:\Users\520\mysite>python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, myapp, sessions
Running migrations:
Applying myapp.0003_alter_book_table... OK
C:\Users\520\mysite>
mysql> show tables;
+-------------