Last active
March 20, 2020 12:04
-
-
Save TrinhTrungDung/7b4ae164dc6a08394d2a7e3423dbe981 to your computer and use it in GitHub Desktop.
Add sample table and migrate to the database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/jinzhu/gorm" | |
_ "github.com/jinzhu/gorm/dialects/postgres" | |
) | |
type User struct { | |
gorm.Model | |
Name string | |
Password string | |
} | |
func main() { | |
db, err := gorm.Open("postgres", "host=localhost port=5432 user=testuser dbname=testdb password=123456 sslmode=disable") | |
if err != nil { | |
fmt.Println(err) | |
} | |
defer db.Close() | |
fmt.Println("Successfully connect to new database") | |
db.AutoMigrate(&User{}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment