python web开发——django学习(二)orm介绍与model检查
原始是这样连接数据库的:
现在改用django orm
(1)先在setting里配置app
(2)在modle.py里建model
class UserMessage(models.Model): object_id = models.CharField(max_length=50, primary_key=True, default="", verbose_name=u"主键") name = models.CharField(max_length=20, null=True, blank=True, default="", verbose_name=u"用户名") email = models.EmailField(verbose_name=u"邮箱") address = models.CharField(max_length=100, verbose_name=u"联系地址") message = models.CharField(max_length=500, verbose_name=u"留言地址") class Meta: verbose_name = u"用户留言信息" verbose_name_plural = verbose_name
(3)运行manage.py,移植
manage.py@djangostart > makemigrations message
manage.py@djangostart > migrate message
(4)看看数据库新建表成功啦