From 9f5b93df6907d5bfc967456db8d4ac81f9003a4e Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Tue, 30 Jan 2024 17:06:24 +0800 Subject: [PATCH] =?UTF-8?q?Debug=20TiDB=20Documentation:=20=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=20Django=20=E8=BF=9E=E6=8E=A5=E5=88=B0=20TiDB=20(#161?= =?UTF-8?q?67)=20(#16440)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...-guide-sample-application-python-django.md | 45 ++++++++++++++----- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/develop/dev-guide-sample-application-python-django.md b/develop/dev-guide-sample-application-python-django.md index 6bbfc585a29b..a18ba1c13730 100644 --- a/develop/dev-guide-sample-application-python-django.md +++ b/develop/dev-guide-sample-application-python-django.md @@ -52,7 +52,7 @@ pip install -r requirements.txt `django-tidb` 是一个为 Django 提供的 TiDB 适配器,它解决了 TiDB 与 Django 之间的兼容性问题。 -安装 `django-tidb` 时,请选择与你的 Django 版本匹配的版本。例如,如果你使用的是 `django==4.2.*`,则应安装 `django-tidb==4.2.*`,其中 minor 版本号不需要完全相同。建议使用最新的 minor 版本。 +安装 `django-tidb` 时,请选择与你的 Django 版本匹配的版本。例如,如果你使用的是 `django==4.2.*`,则应安装 `django-tidb>=4.2.0,<4.3.0`,其中 minor 版本号不需要完全相同。建议使用最新的 minor 版本。 更多信息,请参考 [django-tidb 仓库](https://github.com/pingcap/django-tidb)。 @@ -94,7 +94,7 @@ pip install -r requirements.txt 6. 复制并粘贴对应连接字符串至 `.env` 中。示例结果如下: ```dotenv - TIDB_HOST='{host}' # e.g. gateway01.ap-northeast-1.prod.aws.tidbcloud.com + TIDB_HOST='{host}' # e.g. xxxxxx.aws.tidbcloud.com TIDB_PORT='4000' TIDB_USER='{user}' # e.g. xxxxxx.root TIDB_PASSWORD='{password}' @@ -127,9 +127,9 @@ pip install -r requirements.txt 5. 复制并粘贴对应的连接字符串至 `.env` 中。示例结果如下: ```dotenv - TIDB_HOST='{host}' # e.g. tidb.xxxx.clusters.tidb-cloud.com + TIDB_HOST='{host}' # e.g. xxxxxx.aws.tidbcloud.com TIDB_PORT='4000' - TIDB_USER='{user}' # e.g. root + TIDB_USER='{user}' # e.g. xxxxxx.root TIDB_PASSWORD='{password}' TIDB_DB_NAME='test' CA_PATH='{your-downloaded-ca-path}' @@ -175,6 +175,31 @@ pip install -r requirements.txt python manage.py migrate ``` +```shell +Operations to perform: + Apply all migrations: admin, auth, contenttypes, sample_project, sessions +Running migrations: + Applying contenttypes.0001_initial... OK + Applying auth.0001_initial... OK + Applying admin.0001_initial... OK + Applying admin.0002_logentry_remove_auto_add... OK + Applying admin.0003_logentry_add_action_flag_choices... OK + Applying contenttypes.0002_remove_content_type_name... OK + Applying auth.0002_alter_permission_name_max_length... OK + Applying auth.0003_alter_user_email_max_length... OK + Applying auth.0004_alter_user_username_opts... OK + Applying auth.0005_alter_user_last_login_null... OK + Applying auth.0006_require_contenttypes_0002... OK + Applying auth.0007_alter_validators_add_error_messages... OK + Applying auth.0008_alter_user_username_max_length... OK + Applying auth.0009_alter_user_last_name_max_length... OK + Applying auth.0010_alter_group_name_max_length... OK + Applying auth.0011_update_proxy_permissions... OK + Applying auth.0012_alter_user_first_name_max_length... OK + Applying sample_project.0001_initial... OK + Applying sessions.0001_initial... OK +``` + ### 第 5 步:运行示例应用程序 1. 在开发模式下运行示例应用程序: @@ -212,18 +237,18 @@ python manage.py migrate DATABASES = { "default": { "ENGINE": "django_tidb", - "HOST": ${tidb_host}, - "PORT": ${tidb_port}, - "USER": ${tidb_user}, - "PASSWORD": ${tidb_password}, - "NAME": ${tidb_db_name}, + "HOST": '${tidb_host}', + "PORT": '${tidb_port}', + "USER": '${tidb_user}', + "PASSWORD": '${tidb_password}', + "NAME": '${tidb_db_name}', "OPTIONS": { "charset": "utf8mb4", }, } } -TIDB_CA_PATH = ${ca_path} +TIDB_CA_PATH = '${ca_path}' if TIDB_CA_PATH: DATABASES["default"]["OPTIONS"]["ssl_mode"] = "VERIFY_IDENTITY" DATABASES["default"]["OPTIONS"]["ssl"] = {