AutoMigrate error:
@jinzhu is already working on this.
Since Apr 29, 2025.
Assessment
This issue has not been assessed yet.
Description
Your Question
The following SQL queries are executed:
`SELECT count(*) FROM INFORMATION_SCHEMA.tables WHERE table_name = $1 AND table_type = 'BASE TABLE' AND table_schema = CURRENT_SCHEMA()
terminals
SELECT count(*) FROM INFORMATION_SCHEMA.columns WHERE table_name = $1 AND column_name = $2 AND table_schema = CURRENT_SCHEMA()
terminals id
SELECT count(*) FROM INFORMATION_SCHEMA.columns WHERE table_name = $1 AND column_name = $2 AND table_schema = CURRENT_SCHEMA()
terminals version
SELECT * FROM "terminals" WHERE (deleted_at IS NULL) ORDER BY created_at DESC LIMIT 1`
The versions I am using are as follows:
github.com/lib/pq v1.10.9
gorm.io/driver/postgres v1.5.11
gorm.io/gorm v1.26.0
The structure is as follows:
type Terminal struct { ID int json:"id" gorm:"primaryKey"Version int json:"version" gorm:"default:1" comment:"协议版本号"Mac string gorm:"index" comment:"终端mac地址"MachineID string gorm:"unique;default:''" json:"machine_id" comment:"终端机器码"IP string json:"ip" comment:"终端IP"Os string json:"os" comment:"终端系统信息"ExpiredAt time.Time json:"expired_at" comment:"过期时间"CreatedAt time.Time json:"created_at" comment:"注册时间"UpdatedAt time.Time json:"updated_at" comment:"最后登录时间"DeletedAt gorm.DeletedAtjson:"deleted_at" gorm:"index"}
Table schema:
Table "public.terminals" Column | Type | Collation | Nullable | Default ------------+--------------------------+-----------+----------+--------------------------------------- id | integer | | not null | nextval('terminals_id_seq'::regclass) version | integer | | | 1 mac | text | | | machine_id | text | | | ip | text | | | os | text | | | expired_at | timestamp with time zone | | | created_at | timestamp with time zone | | | updated_at | timestamp with time zone | | | deleted_at | timestamp with time zone | | | Indexes: "terminals_pkey" PRIMARY KEY, btree (id) "terminals_machine_id_key" UNIQUE CONSTRAINT, btree (machine_id) "idx_terminals_deleted_at" btree (deleted_at) "idx_terminals_mac" btree (mac) "terminals_mac_key" btree (mac)
In the Go code, the following function is executed:
db.AutoMigrate(Terminal{})
Tracing leads to the function in github.com/lib/pq/conn.go:
func (cn *conn) query(query string, args []driver.Value) (_ *rows, err error) {}
The SQL query generated is SELECT * FROM "terminals" LIMIT $1, but the args array contains two parameters: 5 and 1.
Therefore, the error occurs: "got %d parameters but the statement requires %d".
Please help me find out where my problem lies
The document you expected this should be explained
Expected answer
- Dominant language
- Go
- Stars
- 298
- Forks
- 158
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from go-gorm/postgres
-
TimeZone is matched anywhere in the DSN, so a password containing "TimeZone=" breaks the connection and appears in its errorPossibly taken @anggakrnwn claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
PostgreSQL 18: `23503` changed to `23001`Possibly taken @jinzhu claimed this 5 days ago. Open
-
HasConstraint ignores UniqueName from custom namerMay be free again @jinzhu claimed this 488 days ago, and no pull request is open. Open
-
Upgrade pgx to v5.6.0 to fix nil arg handlingMay be free again @jinzhu claimed this 607 days ago, and no pull request is open. Open
go-gorm/postgres#303 · 2 comments · 1 reaction · 1 assignee ·
-
Add example usage codeMay be free again @jinzhu claimed this 658 days ago, and no pull request is open. Open
All issues in go-gorm/postgres
Similar issues
-
bug os:ios
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
hajimehoshi/ebiten#4039 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 69/100
open-telemetry/opentelemetry-go-compile-instrumentation#1713 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
JakeChampion/lang#14392 ·
Maintainers usually reply within 1 day
-
agent-butler-finding bug
Difficulty 1/5 1-3 hours Newbie friendliness 84/100
jordansmall/spindrift#6557 ·
Maintainers usually reply within 1 day