#|Django models.py 表结构数据更新后应用到数据库中

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)

    推荐阅读