Your Question
Hi, I face a problem. I have model employee with schema dbo_hcis_new. the insert statement is correct. but set identity not specifying the dbo_hcis_new schema. error message :
SET IDENTITY_INSERT "mtd_employee" ON;INSERT INTO "dbo_hcis_new"."mtd_employee" ("full_name","position_id","position_name","unit_id","unit_code","unit_name","personnel_number") OUTPUT INSERTED."personnel_number" VALUES ('Ardila',30022643,'Human Capital Specialist',10001299,'THC','Performance & Rewards',581974);SET IDENTITY_INSERT "mtd_employee" OFF;
panic: mssql: Cannot find the object "mtd_employee" because it does not exist or you do not have permissions.; mssql: The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.
my models
package models
import (
"time"
)
type Employee struct {
PersonnelNumber int `gorm:"column:personnel_number;primaryKey"`
FullName string `gorm:"column:full_name"`
PositionID int `gorm:"column:position_id"`
PositionName string `gorm:"column:position_name"`
UnitID int `gorm:"column:unit_id"`
UnitCode string `gorm:"column:unit_code"`
UnitName string `gorm:"column:unit_name"`
CreatedAt time.Time `gorm:"column:created_at"`
UpdatedAt time.Time `gorm:"column:updated_at"`
}
func (Employee) TableName() string {
return "dbo_hcis_new.mtd_employee"
}
my insert function
employee := models.Employee{
PersonnelNumber: personnelNumber,
FullName: record[1],
PositionID: positionID,
PositionName: record[3],
UnitID: unitID,
UnitCode: record[5],
UnitName: record[6],
}
result := db.Create(&employee)
if result.Error != nil {
panic(result.Error)
}
fmt.Printf("Employee %d created\n", personnelNumber)
The document you expected this should be explained
Expected answer
it should using schema either on set identity or insert query. or don't run set identity command since my primary key is not autoincrement
Comment From: liepumartins
@inuru did You manage to solve this? Having the same problem.