Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: not able to set an empty array as the default value for a field #2488

Open
AH-dark opened this issue Feb 4, 2025 · 1 comment
Open

Comments

@AH-dark
Copy link

AH-dark commented Feb 4, 2025

Description

If I use

ColumnDef::new(Items::Children)
  .not_null()
  .array(ColumnType::Uuid)
  .default(Value::Array(ArrayType::Uuid, Some(Box::default()))) 

to try to build a field with an empty array as the default value, the generated SQL is:

ALTER TABLE "items" DROP COLUMN "children", ADD COLUMN "children" uuid[] NOT NULL DEFAULT ARRAY []%

This made it impossible to construct this field via regular ORM operations, and I had to use SimpleExpr::Custom.

Expected Behavior

The normal operation should be ALTER TABLE "items" DROP COLUMN "children", ADD COLUMN "children" uuid[] NOT NULL DEFAULT ARRAY[]::uuid[].

Actual Behavior

Migrator will encounter an error Execution Error: error returned from database: cannot determine type of empty array.

Versions

I'm currently using the version 1.1.2, but this operation is unavailable in all versions.

@AH-dark
Copy link
Author

AH-dark commented Feb 4, 2025

This issue has been raised at SeaQL/sea-query#853 and #2068 and implemented at SeaQL/sea-query#854, but it has not been merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant