当前位置:网站首页>Django -- MySQL database reflects the mapping data model to models
Django -- MySQL database reflects the mapping data model to models
2022-06-28 11:47:00 【weixin_ forty-three million eight hundred and twenty thousand a】
Because just use models To define a table is too much trouble
This article is mainly about mysql Create a table in and then directly in models Generate code in
step1:
stay mysql Create a table

step2:
stay cmd Input in python manage.py inspectdb>polls/models.py among polls Created for you app name
step3:
Click on models.py That is, the generation is complete
Attached separately models The code written in maps to MySQL The method in
step1:
Enter the name of the table you want to create
class StudentInfo(models.Model):
stu_id = models.CharField(primary_key=True, max_length=20)
stu_name = models.CharField(max_length=20)
stu_psw = models.CharField(max_length=20)
step2:
cmd Input in python manage.py makemigrations polls(polls For you app name )
The successful result is shown in the figure

step3:
cmd Input in python manage.py migrate
Refresh MySQL In the table
The addition is complete
边栏推荐
- 智联招聘基于 Nebula Graph 的推荐实践分享
- day32 js笔记 事件(上)2021.09.27
- Day28 strict mode, string JS 2021.09.22
- Intranet penetration in the working group environment: some basic methods
- Day34 JS notes regular expression 2021.09.29
- 关于Pytorch中双向LSTM的输出表示问题
- New listing of operation light 3.0 - a sincere work of self subversion across the times!
- 2022 open source software security status report: over 41% of enterprises do not have enough confidence in open source security
- [sciter]: how sciter uses i18 to realize multi language switching of desktop applications and its advantages and disadvantages
- Interview skills for interview steps
猜你喜欢

Characteristics of solar wireless LED display

js中的数组方法 2021.09.18

Practice and Thinking on the architecture of a set of 100000 TPS im integrated message system

day39 原型鏈及頁面烟花效果 2021.10.13

Tidb v6.0.0 (DMR): initial test of cache table - tidb Book rush

QML控件类型:TabBar

Redis6 1: what problems can be solved by the introduction of NoSQL and redis?

Fancy features and cheap prices! What is the true strength of Changan's new SUV?

一套十万级TPS的IM综合消息系统的架构实践与思考

Day29 JS notes 2021.09.23
随机推荐
赛尔号抽奖模拟求期望
day25 js中的预解析、递归函数、事件 2021.09.16
Database Series: is there any way to seamlessly upgrade the business tables of the database
MySQL installation configuration and solving the problem of forgetting root password when reinstalling MySQL
一套十万级TPS的IM综合消息系统的架构实践与思考
Which programming language will attract excellent talents?
Making and using of dynamic library (shared library)
Day39 prototype chain and page Fireworks Effect 2021.10.13
day30 js笔记 BOM和DOM 2021.09.24
使用ssm项目对Mysql8进行访问的时候,出现连接失败和一些错误的解决办法
IO stream of file and Base64
选择哪种编程语言,会吸引优秀的人才?
Chapter 2 do you remember the point, line and surface (2)
Dongyuhui, New Oriental and Phoenix Satellite TV
day31 js笔记 DOM下 2021.09.26
功能真花哨,价格真便宜!长安全新SUV真实力到底怎样?
Web page tips this site is unsafe solution
Industry analysis - quick intercom, building intercom
mysql-.sql文件钓鱼上线
Intranet penetration in the working group environment: some basic methods