优化更新

This commit is contained in:
2026-09-13 17:33:13 +08:00
parent 8be23a62a3
commit 7f758cc6e9
97 changed files with 2333 additions and 3595 deletions
@@ -44,7 +44,7 @@ mysqlbinlog --start-datetime="2026-09-05 00:00:00" \
:::tip binlog 配置
确保 MySQL 配置中启用了 binlog:
```ini
```bash
[mysqld]
server-id = 1
log-bin = mysql-bin
@@ -167,7 +167,7 @@ stages:
### pytest 配置
```ini
```bash
# pytest.ini
[pytest]
DJANGO_SETTINGS_MODULE = application.settings
@@ -7,7 +7,6 @@
:::tip 迁移工具链
- **结构迁移**:Django 内置迁移系统(`makemigrations` + `migrate`)
- **字段注释**:Django 4.1+ 通过 `db_comment` 参数自动添加数据库字段注释
- **自定义命令**:`python manage.py add_full_comments` 回填数据库字段注释
:::
## 全新安装初始化
@@ -99,7 +98,7 @@ python manage.py migrate --fake example
## 字段注释管理
Django 4.1+ 支持通过 `db_comment` 参数为数据库字段添加注释。项目中的模型已自动生成 `db_comment`:
Django 4.1+ 支持通过 `db_comment` 参数为数据库字段添加注释。项目中的模型已自动生成 `db_comment`,在执行 `migrate` 时会自动同步到数据库:
```python
class Example(BaseModel):
@@ -110,16 +109,6 @@ class Example(BaseModel):
)
```
### 回填字段注释
对于已有数据库,可使用自定义命令回填字段注释:
```bash
python manage.py add_full_comments
```
该命令会遍历所有模型,为缺少注释的字段补充 `db_comment`。
## 迁移文件结构
每个应用的迁移文件位于 `application/{app_name}/migrations/` 目录:
@@ -150,7 +139,6 @@ application/example/
| 回滚指定应用 | `python manage.py migrate <app> zero` |
| 查看迁移状态 | `python manage.py showmigrations` |
| 查看迁移 SQL | `python manage.py sqlmigrate <app> <migration>` |
| 回填字段注释 | `python manage.py add_full_comments` |
## 常见问题与排错
@@ -239,7 +239,7 @@ class MasterSlaveRouter:
## Supervisor 多实例配置
```ini
```bash
; /etc/supervisor/conf.d/djangoadmin.conf
[program:djangoadmin-1]
command=/opt/venv/bin/gunicorn application.wsgi:application -c gunicorn.conf.py -b 127.0.0.1:8001
@@ -12,7 +12,7 @@ Supervisor 是一个 Python 编写的进程管理工具,用于在 Linux 服务
## 配置文件示例
```ini
```bash
; Supervisor 进程管理配置
; 将 command / directory 替换为实际路径后复制到 /etc/supervisor/conf.d/
@@ -134,7 +134,7 @@ gunicorn application.wsgi:application \
Supervisor 内置日志轮转功能,通过以下配置控制:
```ini
```bash
; 单个日志文件最大 50MB
stdout_logfile_maxbytes=50MB
; 保留 10 个历史日志文件
@@ -153,7 +153,7 @@ stdout_logfile_backups=10
如需同时管理多个进程(如应用 + Celery Worker):
```ini
```bash
[program:djangoadmin]
command=/path/to/venv/bin/gunicorn application.wsgi:application --bind 127.0.0.1:8000 --workers 4
directory=/data/apps/DjangoAdmin_Django_EleVue