Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用gen生成的代码无法运行,报大量的undefined错误 #1231

Open
zhangchiyue opened this issue Oct 19, 2024 · 1 comment
Open

Comments

@zhangchiyue
Copy link

这是生成代码的方法
`
func main() {
// 配置生成器
g := gen.NewGenerator(gen.Config{
OutPath: "./query", // 生成代码输出目录
Mode: gen.WithoutContext | gen.WithDefaultQuery | gen.WithQueryInterface, // 生成模式
})

// 连接数据库
dsn := "root:123456@(127.0.0.1:3306)/ad?charset=utf8mb4&parseTime=True&loc=Local"
gormdb, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
if err != nil {
	panic("failed to connect to database")
}

// 使用数据库连接
g.UseDB(gormdb)

//// 生成数据库中所有表的代码
g.ApplyBasic(g.GenerateAllTable()...)
g.GenerateAllTable()

// 执行生成操作
g.Execute()

}

这是使用代码的方法
func main() {
dsn := "root:123456@tcp(localhost:3306)/ad?charset=utf8mb4&parseTime=True&loc=Local"
var err error
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
if err != nil {
panic(err)
}
query.SetDefault(db)
adCountry, err := query.Q.AdCountry.First()
if err != nil {
return
}
fmt.Print(adCountry.Country)
}

这是报错

s2sapi/query

query/gen.go:41:28: undefined: adDeviceAndroid
query/gen.go:44:28: undefined: adDeviceIo
query/gen.go:53:28: undefined: adSystemIo
query/gen.go:132:29: undefined: newAdDeviceAndroid
query/gen.go:179:27: undefined: adDeviceAndroid
query/gen.go:182:27: undefined: adDeviceIo
query/gen.go:191:27: undefined: adSystemIo
query/gen.go:327:27: undefined: IAdDeviceAndroidDo
query/gen.go:330:27: undefined: IAdDeviceIoDo
query/gen.go:339:27: undefined: IAdSystemIoDo
query/gen.go:132:29: too many errors`
没有文件缺失,目录路径也是正确的。在goland里面没有任何提示报错,但是运行失败

@qqxhb
Copy link
Member

qqxhb commented Oct 19, 2024

实际上代码是否存在呢?
如果存在感觉可能是环境配置问题,可以调试看看

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants