Fix primary key detection.
This commit is contained in:
parent
82115b24e0
commit
c07d21cffc
2 changed files with 5 additions and 4 deletions
|
@ -138,7 +138,7 @@ func (p *PostgresDriver) PrimaryKeyInfo(tableName string) (*PrimaryKey, error) {
|
|||
where constraint_name = $1;`
|
||||
|
||||
var rows *sql.Rows
|
||||
if rows, err = p.dbConn.Query(queryColumns, tableName); err != nil {
|
||||
if rows, err = p.dbConn.Query(queryColumns, pkey.Name); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -154,12 +154,12 @@ func (p *PostgresDriver) PrimaryKeyInfo(tableName string) (*PrimaryKey, error) {
|
|||
columns = append(columns, column)
|
||||
}
|
||||
|
||||
pkey.Columns = columns
|
||||
|
||||
if err = rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pkey.Columns = columns
|
||||
|
||||
return pkey, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -304,7 +304,8 @@ func AutoIncPrimaryKey(cols []dbdrivers.Column, pkey *dbdrivers.PrimaryKey) stri
|
|||
|
||||
for _, c := range cols {
|
||||
if rgxAutoIncColumn.MatchString(c.Default) &&
|
||||
c.IsNullable == false && c.Type == "int64" {
|
||||
c.IsNullable == false &&
|
||||
(strings.HasPrefix(c.Type, "int") || strings.HasPrefix(c.Type, "uint")) {
|
||||
for _, p := range pkey.Columns {
|
||||
if c.Name == p {
|
||||
return p
|
||||
|
|
Loading…
Add table
Reference in a new issue