2

Django Recursive generation

 11 months ago
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

2023-06-09

| python

django

| 阅读次数: 6

484

|

1 分钟

Django 数据库逆向工程

Python-Django-Framework.jpg

配置好数据库连接(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
坚持原创技术分享,您的支持将鼓励我继续创作!

© 2015 – 2023 Jeff Sui

| 793k

| 12:01

Hexo 强力驱动 v3.9.0

|

主题 – NexT.Gemini v7.1.1

16955

|

18613


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK