2
Django Recursive generation
source link: https://pinghailinfeng.gitee.io/2023/06/09/Django-Recursive-generation/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Django Recursive generation
Django 数据库逆向工程
配置好数据库连接(MySQL为例)
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'database_name',
'HOST': '127.0.0.1',
'PORT': '3306',
'USER': 'your_database_name',
'PASSWORD': 'your_database_password',
}
}
安装MySQL依赖
pip install PyMySQL
项目下的__init__.py
添加如下代码
import pymysql
pymysql.install_as_MySQLdb()
执行inspectdb 命令重定向到文件,就可以反向生成models中的model类
python manage.py inspectdb > models.py
如果指向一张表生成对应models中的model类
python manage.py inspectdb table_name > models.py
坚持原创技术分享,您的支持将鼓励我继续创作!
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK