Golang运行git main.go时出现的终端错误怎么解决
Golang运行git main.go时出现的终端错误怎么解决 为什么启动项目时会遇到这个错误
用户迁移
package migrations
import (
"fmt"
"gorest/models"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
var DB *gorm.DB
var err error
const dbinfo = "host=localhost user=postgres password=***** dbname=BigDb port=5432 sslmode=disable"
func InitalMigration() {
DB, err = gorm.Open(postgres.Open(dbinfo), &gorm.Config{})
if err != nil {
fmt.Println(err.Error())
}
DB.AutoMigrate(&models.User{})
}
错误
*2022/12/27 13:56:05 C:/Users/baris/OneDrive/Masaüstü/GOREST/migrations/usermigration.go:19
[error] 初始化数据库失败,错误原因:无法连接到 host=localhost user=postgres database=BigDb:服务器错误 (FATAL: database “BigDb” does not exist (SQLSTATE 3D000))
无法连接到 host=localhost user=postgres database=BigDb:服务器错误 (FATAL: database “BigDb” does not exist (SQLSTATE 3D000))
2022/12/27 13:56:05 C:/Users/baris/OneDrive/Masaüstü/GOREST/migrations/usermigration.go:24 无法连接到 host=localhost user=postgres database=BigDb:服务器错误 (FATAL: database “BigDb” does not exist (SQLSTATE 3D000))
[46.255ms] [rows:-] SELECT count(*) FROM information_schema.tables WHERE table_schema = CURRENT_SCHEMA() AND table_name = ‘users’ AND table_type = ‘BASE TABLE’
2022/12/27 13:56:05 C:/Users/baris/OneDrive/Masaüstü/GOREST/migrations/usermigration.go:24 无法连接到 host=localhost user=postgres database=BigDb:服务器错误 (FATAL: database “BigDb” does not exist (SQLSTATE 3D000))
[45.179ms] [rows:0] CREATE TABLE “users” (“id” bigserial,“created_at” timestamptz,“updated_at” timestamptz,“deleted_at” timestamptz,“first_name” text,“last_name” text,“email” text,“password” text,PRIMARY KEY (“id”))*
更多关于Golang运行git main.go时出现的终端错误怎么解决的实战教程也可以访问 https://www.itying.com/category-94-b0.html
我该如何解决这个错误
原因在于你复制到这里却没有阅读的错误信息中。
你的 PostgreSQL 实例中没有名为 BigDb 的数据库。


