django-orm基础字段及选项1

orm基础字段及选项

django-orm基础字段及选项1

django-orm基础字段及选项1

django-orm基础字段及选项1

字段类型

django-orm基础字段及选项1

django-orm基础字段及选项1

django-orm基础字段及选项1

django-orm基础字段及选项1

django-orm基础字段及选项1

django-orm基础字段及选项1

django-orm基础字段及选项1

from django.db import models

# Create your models here.
class Book(models.Model):
    title=models.CharField(‘书名‘,max_length=50,default=‘‘)
    price=models.DecimalField(‘价格‘,max_digits=7,decimal_places=2)
    info=models.CharField(‘描述‘,max_length=100,default=‘‘)

class Author(models.Model):
    name=models.CharField(‘姓名‘,max_length=11)
    age=models.IntegerField(‘年龄‘)
    email=models.EmailField(‘邮箱‘)

django-orm基础字段及选项1
blank主要控制admin后台值为空,与null有一定区别
django-orm基础字段及选项1
django-orm基础字段及选项1
django-orm基础字段及选项1

添加修改字段都需要makemigrations 和migrate

针对模型类表的操作

meta类
django-orm基础字段及选项1

# Create your models here.
class Book(models.Model):
    title=models.CharField(‘书名‘,max_length=50,default=‘‘)
    price=models.DecimalField(‘价格‘,max_digits=7,decimal_places=2)
    info=models.CharField(‘描述‘,max_length=100,default=‘‘)
    class Meta:
        db_table=‘book‘

····
C:\Users\Administrator\Desktop\mysite2>python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, bookstore, contenttypes, sessions
Running migrations:
Applying bookstore.0002_author... OK

C:\Users\Administrator\Desktop\mysite2>python manage.py makemigrations
Migrations for ‘bookstore‘:
bookstore\migrations\0003_auto_20210807_1002.py
- Rename table for book to book

C:\Users\Administrator\Desktop\mysite2>python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, bookstore, contenttypes, sessions
Running migrations:
Applying bookstore.0003_auto_20210807_1002... OK

mysql> show tables;
+----------------------------+
| Tables_in_mysite2 |
+----------------------------+
| auth_group |
| auth_group_permissions |
| auth_permission |
| auth_user |
| auth_user_groups |
| auth_user_user_permissions |
| book |
| bookstore_author |
| django_admin_log |
| django_content_type |
| django_migrations |
| django_session |
+----------------------------+
12 rows in set (0.00 sec)

····
django-orm基础字段及选项1

django-orm基础字段及选项1

上一篇:2014-12-11 C# if语句 题目


下一篇:vscode搜索结果 背景颜色很淡 解决办法