Git Product home page Git Product logo

ent-issue's Introduction

Trouble about Ent with MySQL 5.7

Enviroment

Go

go version
go version go1.17 darwin/amd64
  • Ent: v0.9.1
  • MySQL: 5.7

Schema

package schema

import (
	"time"

	"entgo.io/ent"
	"entgo.io/ent/schema/field"
)

// User holds the schema definition for the User entity.
type User struct {
	ent.Schema
}

// Fields of the User.
func (User) Fields() []ent.Field {
	return []ent.Field{
		field.String("name").Default("unknown"),
		field.Time("created_at").Immutable().Default(time.Now),
	}
}

// Edges of the User.
func (User) Edges() []ent.Edge {
	return nil
}

Reproduction Method

git clone [email protected]:iwata/ent-issue.git
cd ent-issue
docker compose up -d
go mod download
go run cmd/main.go

cmd/main.go executes a simple task, so migrates schema, creates a user, and selects a user. But it occures an error.

Current Behavior

go run cmd/main.go
2021/08/31 20:08:49 failed to get a user: sql: Scan error on column index 2, name "created_at": unsupported Scan, storing driver.Value type []uint8 into type *time.Time
exit status 1

And it creates users, but not expected about created_at.

mysql -h 127.0.0.1 -P 3306 -u root -ppass test -e 'desc users'
+------------+--------------+------+-----+---------+----------------+
| Field      | Type         | Null | Key | Default | Extra          |
+------------+--------------+------+-----+---------+----------------+
| id         | bigint(20)   | NO   | PRI | NULL    | auto_increment |
| name       | varchar(255) | NO   |     | unknown |                |
| created_at | timestamp    | YES  |     | NULL    |                |
+------------+--------------+------+-----+---------+----------------+

Expected Behavior

go run cmd/main.go
select a user successfully

And it should create users looks like below.

mysql -h 127.0.0.1 -P 3306 -u root -ppass test -e 'desc users'
+------------+--------------+------+-----+---------+----------------+
| Field      | Type         | Null | Key | Default | Extra          |
+------------+--------------+------+-----+---------+----------------+
| id         | bigint(20)   | NO   | PRI | NULL    | auto_increment |
| name       | varchar(255) | NO   |     | unknown |                |
| created_at | timestamp    | NO   |     | NULL    |                |
+------------+--------------+------+-----+---------+----------------+

created_at shouldn't be nullable.

ent-issue's People

Contributors

iwata avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.