Ent: Cannot add a field type of float with 0 as default value

Created on 1 Mar 2021  路  3Comments  路  Source: ent/ent

  • [ ] The issue is present in the latest release.
  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 馃槸

Add a field type of float with 0 as the default value make the migration fail.

Expected Behavior 馃

It's should migrate with no problem

Steps to Reproduce 馃暪

Steps:

  1. Add a float field field.Float("point").Default(0)
  2. Run go run entgo.io/ent/cmd/ent generate --feature privacy ./ent/schema

Your Environment 馃寧

| Tech | Version |
| ----------- | ------- |
| Go | 1.15.5 |
| Ent | 0.6.0 |
| Database | Postgres |

Most helpful comment

Thanks for reporting this @HarikiRito 馃檹

1287 fixed the issue. Closing

All 3 comments

Hey @HarikiRito,
I tried reproducing this on my local machine and it seems to work fine. Can you share more details on the current behavior? Specifically a stack trace on the error, and if you can share an example schema it will also be helpful.

EDIT: in addition, what postgres version are you using? Also, are you trying to add a new field with a default value, or are you trying to add a default value to an existing column?

@rotemtam I believe the cause of this problem is when schema generate it doesn't have a "Default" field. And I'm using postgres:13.1 docker container
This happened if I add a new field with 0 as the default
post

migrate/schema.go
post

Here is the error message when I run the app

alter table "posts": ERROR: column "actual_point" of relation "posts" contains null values (SQLSTATE 23502)

Thanks for reporting this @HarikiRito 馃檹

1287 fixed the issue. Closing

Was this page helpful?
0 / 5 - 0 ratings

Related issues

clearcodecn picture clearcodecn  路  3Comments

ernado picture ernado  路  3Comments

tomakado picture tomakado  路  4Comments

dilipkk-foyernet picture dilipkk-foyernet  路  4Comments

ernado picture ernado  路  4Comments