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

Can't connect to posgres db #3539

Closed
lethienhoang opened this issue Sep 27, 2020 · 6 comments
Closed

Can't connect to posgres db #3539

lethienhoang opened this issue Sep 27, 2020 · 6 comments
Assignees
Labels

Comments

@lethienhoang
Copy link

GORM Playground Link

go-gorm/playground#1

Description

`import (
"log"
"my-portfolio-api/config"
"my-portfolio-api/models"

"gorm.io/driver/postgres"
"gorm.io/gorm"

)`

db, err := gorm.Open(postgres.New(postgres.Config{ DSN: config.DBURL, DriverName: config.DBDRIVER, }), &gorm.Config{})

I'm still getting the error "sql: unknown driver "postgres" (forgotten import?)". I'm getting error. How to fix it?

@github-actions github-actions bot added the type:missing reproduction steps missing reproduction steps label Sep 27, 2020
@github-actions
Copy link

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 2 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.ioSearch Before Asking

@lethienhoang
Copy link
Author

DBURL = fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=disable", host, port, user, password, dbname)

@github-actions
Copy link

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 2 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.ioSearch Before Asking

@luisgomez29
Copy link
Contributor

@lethienhoang You can comment out the DriverName line as you are going to use Gorm's postgres driver:

db, err := gorm.Open(postgres.New(postgres.Config{
		DSN:        config.DBURL,
		//DriverName: "postgres",
	}), &gorm.Config{})

Another connection option:

func Connect() *gorm.DB {
	db, err := gorm.Open(postgres.Open(config.DBURL), &gorm.Config{})

	if err != nil {
		log.Fatal(err)
	}
	return db
}

https://gorm.io/docs/connecting_to_the_database.html#PostgreSQL

@github-actions
Copy link

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 2 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.ioSearch Before Asking

@leenux
Copy link

leenux commented Jan 7, 2021

same issue,why auto closed by bot?

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

No branches or pull requests

4 participants