go
module_error
ai_generated
true
sql:未知驱动 "postgres"(是否忘记导入?)
sql: unknown driver "postgres" (forgotten import?)
ID: go/sql-driver-unknown
80%修复率
90%置信度
0证据数
2024-02-05首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.18 | active | — | — | — |
| 1.22 | active | — | — | — |
根因分析
未以空白导入方式导入数据库驱动包,database/sql 没有已注册的驱动。
English
The database driver package was not imported with a blank import, so database/sql has no registered driver.
解决方案
-
95% 成功率
import ( "database/sql" _ "github.com/lib/pq" ) db, _ := sql.Open("postgres", dsn) -
90% 成功率
Use pgx/v5/stdlib blank import when using pgx driver.
无效尝试
常见但无效的做法:
-
60% 失败
Named imports can trigger 'imported and not used' unless referenced.
-
90% 失败
Only changes the error message.