1、安装addcomments
pip install addcomments
2、确认model的verbose_name,如果需要添加注释,需要给字段添加verbose_name属性
class Student(models.Model):
name = models.CharField(max_length=200, verbose_name="名称", blank=True, default=None)
age = models.SmallIntegerField(verbose_name="年龄", blank=True, default=None)
class Meta:
db_table = 'test_student'
3、settings.py中添加模块
INSTALLED_APPS += [
'addcomments',
]
4、运行命令即可立即添加注释
python manage.py addcolumncomments
-- FOR test_student.name
ALTER TABLE test_student
MODIFY COLUMN `name` varchar(200) COLLATE utf8mb4_bin NOT NULL COMMENT '名称'
-- FOR test_student.age
ALTER TABLE test_student
MODIFY COLUMN `age` smallint(6) NOT NULL COMMENT '年龄'
标签:name,models,addcomments,Django,注释,student,MySQL,test,verbose
From: https://www.cnblogs.com/chenxdnote/p/17506092.html