From 6a0311d59966cfe638bd7a57ef6c7a7cb37a95c1 Mon Sep 17 00:00:00 2001 From: seaislee1209 Date: Thu, 19 Mar 2026 16:16:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20LoginRecord=20=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E6=97=B6=E6=98=BE=E5=BC=8F=E4=BC=A0=20geo=20=E7=A9=BA=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=EF=BC=8C=E4=BF=AE=E5=A4=8D=20MySQL=20=E4=B8=A5?= =?UTF-8?q?=E6=A0=BC=E6=A8=A1=E5=BC=8F=20IntegrityError?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MySQL 严格模式下 CharField 即使模型定义了 default='',CREATE 不传字段仍报错。 显式传入 geo_country/geo_province/geo_city/geo_source='' 解决。 Co-Authored-By: Claude Opus 4.6 --- CLAUDE.md | 1 + backend/apps/accounts/views.py | 1 + 2 files changed, 2 insertions(+) diff --git a/CLAUDE.md b/CLAUDE.md index 8330835..233e5e2 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -444,6 +444,7 @@ npx tsx src/index.ts --resume /Users/maidong/Desktop/zyc/研究openclaw/视频 | 2026-03-18 | v0.9.1: 系统设置页 — 异常检测总开关、R1-R5默认阈值、飞书接收人+测试、告警冷却 | Frontend | | 2026-03-18 | v0.9.1: 团队管理 — 预期登录城市(必填) + 自动学习 + disabled_by 来源标签 | Full stack | | 2026-03-18 | v0.9.1: 前端拦截器 — user_disabled/team_disabled 错误码处理,弹窗提示后跳登录 | Frontend | +| 2026-03-19 | fix: LoginRecord 创建时显式传 geo 空字段,修复 MySQL 严格模式 IntegrityError | Backend | ### Phase 4 Details (2026-03-13) diff --git a/backend/apps/accounts/views.py b/backend/apps/accounts/views.py index a3c9b47..3df05a4 100644 --- a/backend/apps/accounts/views.py +++ b/backend/apps/accounts/views.py @@ -103,6 +103,7 @@ def login_view(request): user_agent = request.META.get('HTTP_USER_AGENT', '') login_record = LoginRecord.objects.create( user=user, team=user.team, ip_address=ip, user_agent=user_agent, + geo_country='', geo_province='', geo_city='', geo_source='', ) # IP 归属地解析 + 异常检测(不阻塞登录)