go-gorm / gorm

The fantastic ORM library for Golang, aims to be developer friendly
https://gorm.io
MIT License
36.55k stars 3.91k forks source link

no data #2986

Closed liuyangsds closed 4 years ago

liuyangsds commented 4 years ago

package main

import ( "fmt" "github.com/jinzhu/gorm" _ "github.com/jinzhu/gorm/dialects/mysql" )

type User struct { id int userddname string mobile string password string nickname string }

func main() { db,err := gorm.Open("mysql","root:liuyang@(localhost:3306)/goodgame?charset=utf8mb4&parseTime=True&loc=Local") if err != nil { fmt.Println(err) } defer db.Close()

db.LogMode(true)

db.SingularTable(true)

var user User

db.First(&user)
fmt.Println(user)

}

gorm1 mysql1

shbht commented 4 years ago

Any update on this. I am also getting the same issue. I am using gorm version 1.9.12

ap-in-git commented 4 years ago

@liuyangsds your table name should be users

fishyww commented 4 years ago

@liuyangsds Defining a struct pays attention to the case of the syntax type User struct { Id int UserddName string Mobile string Password string Nickname string }

liuyangsds commented 4 years ago

@liuyangsds Defining a struct pays attention to the case of the syntax type User struct { Id int UserddName string Mobile string Password string Nickname string }

Thank you for the reminder

LonglyCode commented 4 years ago

why reopened? any problem?