-
Hi, I am still working backwards off of a database import but ran into another migration issue. I built a small test case to reproduce it: package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
)
// Todo holds the schema definition for the Todo entity.
type Todo struct {
ent.Schema
}
// Fields of the Todo.
func (Todo) Fields() []ent.Field {
return []ent.Field{
field.Int("id"),
field.String("title"),
field.Int("author"),
}
}
// Edges of the Todo.
func (Todo) Edges() []ent.Edge {
return []ent.Edge{
edge.From("user", User.Type).
Ref("todo").
Required().
Field("author").
Unique(),
}
} package schema
import (
"entgo.io/ent"
"entgo.io/ent/dialect"
"entgo.io/ent/schema/edge"
"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.Int("id").SchemaType(map[string]string{
dialect.Postgres: "serial",
dialect.SQLite: "integer",
}),
field.String("name"),
}
}
// Edges of the User.
func (User) Edges() []ent.Edge {
return []ent.Edge{
edge.To("todo", Todo.Type),
}
} Follow the tutorial, added a So, I execute the migration: go run -mod=mod ent/migrate/main.go first And have the following -- create "users" table
CREATE TABLE "users" (
"id" serial NOT NULL,
"name" character varying NOT NULL,
PRIMARY KEY ("id")
);
-- create "todos" table
CREATE TABLE "todos" (
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"title" character varying NOT NULL,
"author" serial NOT NULL,
PRIMARY KEY ("id"),
CONSTRAINT "todos_users_todo"
FOREIGN KEY ("author")
REFERENCES "users" ("id")
ON DELETE NO ACTION
); When I run a migration, I expect:
However, the On top of that, something I haven't been able to repro with this yet is: in my older software, the initial import shows tables as So imagine this:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
I also tried forcing field.Int("author").SchemaType(map[string]string{
dialect.Postgres: "integer",
}) |
Beta Was this translation helpful? Give feedback.
I also tried forcing
integer
on it, but that didn't help either: