Beego必须有一个名为`default`的寄存器DataBase别名 [英] Beego must have one register DataBase alias named `default`

查看:4570
本文介绍了Beego必须有一个名为`default`的寄存器DataBase别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Beego的生产服务器中,我得到

必须有一个寄存器DataBase别名,名称为 default



我知道数据库连接凭证可以在服务器上工作,但每当我做出宁静的请求时,我都会得到这个错误,并且Beego服务器崩溃。



以下是main.go初始化函数中的代码:

  orm.RegisterDriver(postgres,orm.DR_Postgres)

orm.RegisterDataBase(default,postgres,
fmt。 Sprintf(postgres://%s:%s @%s /%s?port =%i,
pgUser,pgPass,pgHost,pgDb,pgPort))



解决方案

您可以提供您的代码样本吗?

根据您提供的错误消息,您可能未使用 orm.RegisterDataBase default 的数据库C>。以下是我从文档取得的示例:

  //参数1:数据库别名。 ORM将使用它来切换数据库。 
//参数2:driverName
//参数3:连接字符串
orm.RegisterDataBase(default,mysql,root:root @ / orm_test?charset = utf8)

在beego中,通常将驱动程序和数据库注册到 init main.go (示例)


In the production server with Beego I get

must have one register DataBase alias named default

I know the db connection credentials work in the server but whenever I do restful request I get this error and the Beego server crashes.

Is there a reason why this is happening?

Below is the code inside main.go init function:

orm.RegisterDriver("postgres", orm.DR_Postgres)

orm.RegisterDataBase("default", "postgres",
    fmt.Sprintf("postgres://%s:%s@%s/%s?port=%i",
        pgUser, pgPass, pgHost, pgDb, pgPort))

解决方案

Can you provide a sample of your code?

Based on the error message you have provided, you may not have registered a database with alias default using orm.RegisterDataBase. Here's an example which I have taken from the documentation:

// param 1:        Database alias. ORM will use it to switch database.
// param 2:        driverName
// param 3:        connection string
orm.RegisterDataBase("default", "mysql", "root:root@/orm_test?charset=utf8")

In beego, it is common to register the driver and the database in init of main.go (example).

这篇关于Beego必须有一个名为`default`的寄存器DataBase别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆