3、反向生成
现在数据库中创建表
- CREATE TABLE `alarm_group` (
- `group_name` varchar(250) NOT NULL,
- `group_des` blob,
- `members` blob,
- `timestamp` datetime NOT NULL,
- `on_duty` blob,
- `leader` blob,
- PRIMARY KEY (`group_name`)
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8
然后执行命令,生成model.py代码
- python manage.py inspectdb
生成的代码model.py如下
- class AlarmGroup(models.Model):
- group_name = models.CharField(primary_key=True, max_length=250)
- group_des = models.TextField(blank=True, null=True)
- members = models.TextField(blank=True, null=True)
- timestamp = models.DateTimeField()
- class Meta:
- managed = False
- db_table = ‘alarm_group‘