【Python-Django】医疗辅助平台-数据库设计-day2.1

操作需知:

MySQL存储很长500的汉字选用字符类型_mysql字符串太长用什么存_信息时代弄潮儿的博客-CSDN博客

mysql中的Varchar(255)可以放多少个汉字_Ecloss的博客-CSDN博客_varchar255能存多少汉字 

MySQL中的Text类型_SlowIsFastLemon的博客-CSDN博客_text类型 

 创建病例表(case):

 添加示例病症:

…… 

数据来源:39健康网_中国优质医疗保健信息与在线健康服务平台

扫描二维码关注公众号,回复: 14551669 查看本文章

 去这个网站下载mysql连接插件

https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient

 下载对应的python版本

 然后将文件拷贝到项目文件夹:

 

添加到环境中

 

使用Django连接现已经存在的mysql数据库中的表

参考:如何使用Django连接现已经存在的mysql数据库中的表 - 百度文库

 在init.py中写如下代码:

import  pymysql
pymysql.install_as_MySQLdb()

在终端输入:

python manage.py inspectdb

即可获取到对应数据库中的表的代码:

 将此复制粘贴到models.py中:

from django.db import models


class Case(models.Model):
    name = models.CharField(primary_key=True, max_length=255)
    othername = models.CharField(max_length=255, blank=True, null=True)
    introduction = models.TextField(blank=True, null=True)
    symptom = models.TextField(blank=True, null=True)
    field_insurance = models.CharField(db_column=' insurance', max_length=20, blank=True, null=True)  # Field renamed to remove unsuitable characters. Field renamed because it started with '_'.
    department = models.CharField(max_length=255, blank=True, null=True)
    infection = models.CharField(max_length=20, blank=True, null=True)
    position = models.CharField(max_length=255, blank=True, null=True)
    period = models.CharField(max_length=255, blank=True, null=True)
    crowd = models.CharField(max_length=255, blank=True, null=True)
    drug = models.TextField(blank=True, null=True)
    method = models.TextField(blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'case'

猜你喜欢

转载自blog.csdn.net/qq_51701007/article/details/128741456