Can't connect to PostgreSql through GORM on the Golang



  • What may be related is that GORM has no access to the PostgreSQL database and PgAdmin is available. The constructions are the same. Antivirus, Brandmauer turned off. GORM's on a new ride.

       import(
            //"github.com/jinzhu/gorm/dialects/postgres"
          "github.com/jinzhu/gorm"
          _ "github.com/lib/pq"
       )
    

    Code itself

        db, err := gorm.Open("postgres", "host=localhost:5432  user=postgres password=RomanRakzin dbname=MyDB  sslmode=disable")  
        if err != nil {
           log.Println("Ошибка подключения к базе данных......") 
        }
    

    And I tried without instructions. host=localhost:5432 and simple. host=localhost
    There's a base user with that password. Everything works at PgAdmin, and it's not here.



  • I'd try to rewrite the import line.

    //"github.com/jinzhu/gorm/dialects/postgres"

    _ "github.com/jinzhu/gorm/dialects/postgres"

    You can also try to elicit a mistake, not just her existence. I mean, replace the line.

    log.Println("Ошибка подключения к базе данных......")

    e.g.:

    log.Printf("Ошибка подключения к базе данных: %s", err)




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2