diff --git a/src/commands/dm/_validate.ts b/src/commands/dm/_validate.ts index addd198..7f86d39 100644 --- a/src/commands/dm/_validate.ts +++ b/src/commands/dm/_validate.ts @@ -189,14 +189,17 @@ export function validateFields(opts: { return { ok: false, step: 1, stepName: '字段定义', errors } } - // 镜像 Form.vue:215-216 至少 1 个 primaryKey - const hasPrimaryKey = opts.fields.some((f) => !!f.primaryKey) - if (!hasPrimaryKey) { - errors.push({ - field: 'fields.primaryKey', - message: '请选择一个字段作为主键', - }) - } + // v0.11e+ (2026-06-27 tds 复盘): 移除 "至少 1 个 primaryKey" 校验 + // 原因: JNPF 自动注入 f_id 作为物理 PK (per CLAUDE.md §3 / dm create 自动补 9 系统列 + 2 PK 机制), + // 用户不需要 (也不应该) 在 --fields 中指定 primaryKey=1 的业务字段. + // 旧校验要求用户至少标 1 个 PK, 但 H 子代理 B-8 修复禁止业务字段 PK, 形成矛盾: + // - 旧校验: 用户必须 primaryKey=1 (否则"请选择字段作为主键") + // - B-8 校验: 业务字段 primaryKey=1 禁止 (PK 必须留给 f_id) + // 结果: dm create 永远 fail. + // 修复: 去掉 "至少 1 个 PK" 校验. NMPF 自动 f_id 管 PK, 业务唯一性用 unique 约束或 billRule jnpfKey. + // 之前代码 (注释保留作为历史): + // const hasPrimaryKey = opts.fields.some((f) => !!f.primaryKey) + // if (!hasPrimaryKey) { errors.push({...message: '请选择一个字段作为主键'}) } // 镜像 Form.vue:174-209 exist() 字段级 7 项校验 const seenFields = new Set() diff --git a/src/commands/test/run.ts b/src/commands/test/run.ts index 73d9c36..26370c8 100644 --- a/src/commands/test/run.ts +++ b/src/commands/test/run.ts @@ -268,7 +268,12 @@ function buildSampleData(fields: Array<{ __vModel__?: string; __config__?: { jnp if (sysKeys.has(key)) continue if (['uploadImg', 'uploadFz', 'uploadFile'].includes(key)) continue if (['input', 'textarea'].includes(key)) { - sample[vmodel] = `test_${vmodel}` + // v0.11e+ (2026-06-27 tds): 用短前缀 `t_` + vmodel 截断到 20 字符 + // 之前 `test_${vmodel}` 对 f_connector_type (varchar(20)) 超长 → MySQL truncation 报错. + // formData.fields 没有 dataLength 字段 (在 tables[].fields), 简单方案: 短前缀 + 截断. + // 截断保留字段名前 17 字符 + 短前缀 (例: t_f_connector_ty). + const value = `t_${vmodel}`.slice(0, 20) + sample[vmodel] = value continue } if (['inputNumber', 'numInput', 'calculate'].includes(key)) {