Django models.py 表结构数据更新后应用到数据库中
如下,数据表新增字段:
# arch_center/models.pyclass BaseArch(AbstractBaseModel):
...
x86_tag = models.CharField("x86 架构版本", max_length=100, null=False, default='')
x86_sha256 = models.CharField("x86 架构sha256值", max_length=100, null=False, default='')
aarch64_tag = models.CharField("aarch64 架构版本", max_length=100, null=False, default='')
aarch64_sha256 = models.CharField("aarch64 架构sha256值", max_length=100, null=False, default='')
sw64_tag = models.CharField("sw64 架构版本", max_length=100, null=False, default='')
sw64_sha256 = models.CharField("sw64 架构sha256值", max_length=100, null=False, default='')class Meta:
db_table = "base_arch"
verbose_name_plural = "基础镜像表"
未应用之前数据库表结构:
mysql> desc base_arch;
+--------------------+--------------+------+-----+---------+----------------+
| Field| Type| Null | Key | Default | Extra|
+--------------------+--------------+------+-----+---------+----------------+
| id| int(11)| NO| PRI | NULL| auto_increment |
| user| varchar(100) | YES|| NULL||
| is_newest| varchar(100) | NO|| NULL||
| is_delete| varchar(20)| NO|| NULL||
| is_free| varchar(20)| NO|| NULL||
+--------------------+--------------+------+-----+---------+----------------+
30 rows in set (0.00 sec)
新增操作:
python manage.py makemigrations arch_centerMigrations for 'arch_center':
0079_auto_20220422_1046.py:
- Add field aarch64_sha256 to basearch
- Add field aarch64_tag to basearch
- Add field sw64_sha256 to basearch
- Add field sw64_tag to basearch
- Add field x86_sha256 to basearch
- Add field x86_tag to basearchpython manage.py migrateOperations to perform:
Synchronize unmigrated apps: staticfiles, messages
Apply all migrations: basearch
Synchronizing apps without migrations:
Creating tables...
Running deferred SQL...
Installing custom SQL...
Running migrations:
Rendering model states... DONE
Applying basearch.0079_auto_20220422_1046... OK
【#|Django models.py 表结构数据更新后应用到数据库中】再次查询数据库,成功
mysql> desc basearch;
+-----------------------+--------------+------+-----+---------+----------------+
| Field| Type| Null | Key | Default | Extra|
+-----------------------+--------------+------+-----+---------+----------------+
| id| int(11)| NO| PRI | NULL| auto_increment |
| user| varchar(100) | YES|| NULL||
| is_newest| varchar(100) | NO|| NULL||
| is_delete| varchar(20)| NO|| NULL||
| is_free| varchar(20)| NO|| NULL||
| aarch64_sha256| varchar(100) | NO|| NULL||
| aarch64_tag| varchar(100) | NO|| NULL||
| sw64_sha256| varchar(100) | NO|| NULL||
| sw64_tag| varchar(100) | NO|| NULL||
| x86_sha256| varchar(100) | NO|| NULL||
| x86_tag| varchar(100) | NO|| NULL||
+-----------------------+--------------+------+-----+---------+----------------+
36 rows in set (0.00 sec)
推荐阅读
- python|python 深度 视差 计算_开源双目视觉BM算法-Matlab/Python/Javascript
- 前端开发|推荐个国产框架,从此轻松开发 小程序/App/h5
- Django打造在线教育平台_day_2(新建users app 编写models之完善)
- Django打造在线教育平台_day_2(新建users app 编写models之扩展user表)
- #|网络编程-----网络通信协议
- OpenCV|解决error: (-215:Assertion failed) _src.empty() in function ‘cv::cvtColor‘
- Java毕业设计项目实战篇|Java项目:大学生实习管理系统(java+SpringBoot+Thymeleaf+html+JQuery+bootstrap)
- 树莓派|Python3树莓派连接阿里云物联网设备发送接收数据
- 树莓派|【树莓派】树莓派4无痛安装系统(NOOBS篇)