Skip to content

列做 不 Exist

错误信息

                列做 不 exist
              

快速摘要

你的查询引用列 那个做 不 exist in specified 表 — 它可能是 misspelled, 不 yet 添加, or in 不同表.

为什么发生

  • Typo in 列 name

  • 列有 不是 添加到 表 (missing ALTER TABLE 迁移)

  • 列 exists in 不同表 than one queried

  • 情况 sensitivity mismatch (一些数据库 treat 列 names as 情况-sensitive)

最小示例

✗ 错误代码
SELECT fist_name FROM users;
-- Typo: 'fist_name' instead of 'first_name'
✓ 修复代码
SELECT first_name FROM users;

列 fist_name 做不 exist — fixing typo 到 first_name resolves 错误.

如何诊断

  • 检查 spelling 的列 name

  • 描述表 到 see 它的列: \d table_name in psql or DESCRIBE table_name in MySQL

  • 验证列 是 in 表你 是 querying, 不 related 表

  • 检查 for 情况 sensitivity issues — try quoting 列 name

如何修复

  • Fix typo 到 match 实际列 name

  • 运行迁移到 添加 missing 列: ALTER TABLE ... ADD COLUMN ...

  • 引用列 从正确表 (use JOIN 如果需要)

  • Quote 列 name 如果情况是 issue

如何预防

  • Use ORM 那个验证列 names at 编译时间

  • Keep 你的 Schema documented and 上到 date

  • Use consistent naming 约定 (snake_case 是常见 for 列)

相关资源

相关术语

相关课程

  • 表

    学习关于表 列.

← 返回语言