Primary key assigned to a wrong column
remy-sl opened this issue · 2 comments
remy-sl commented
Describe the bug
reform-db init assigns primary key to a wrong column
To Reproduce
- Given database schema
CREATE TABLE `builds` ( `i` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `id` varchar(32) NOT NULL, `name` text NOT NULL, PRIMARY KEY (`i`), UNIQUE KEY `id` (`id`) );
- Run
reform-db -db-driver MySQL -db-source ... init /package/path
- Resulting model:
type Builds struct { I int64 `reform:"i"` ID string `reform:"id,pk"` Name string `reform:"name"` }
Expected behavior
Expected model is:
type Builds struct {
I int64 `reform:"i,pk"`
ID string `reform:"id"`
Name string `reform:"name"`
}
Additional context
I don't know what happened here. I am new to go so I actually don't want to dig deeper in the source code but I assume primary key recognition relies on a column name being id
rather than actual PRIMARY KEY
constraint.
AlekSi commented
No, it should rely on PRIMARY KEY. Sounds like a bug.
AlekSi commented
It will be fixed tomorrow in 1.4.1