Skip to content

AutoMigrate error: #307

Open
Open
@crainday

Description

@crainday

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions