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

Cannot set column to nullable #2396

Open
ou-bing opened this issue Oct 16, 2024 · 2 comments
Open

Cannot set column to nullable #2396

ou-bing opened this issue Oct 16, 2024 · 2 comments

Comments

@ou-bing
Copy link

ou-bing commented Oct 16, 2024

Description

.col(date_time(UrlMapping::ExpiredAt).null())

When I execute ·sea-orm-cli migrate-v·, the console prompts:

2024-10-16T14:13:34.698031Z  INFO sqlx::query: summary="CREATE TABLE IF NOT …" db.statement="\n\nCREATE TABLE IF NOT EXISTS \"url_mapping\" (\n  \"id\" serial NOT NULL PRIMARY KEY,\n  \"source_url\" char(255) NOT NULL NOT NULL,\n  \"target_url_protocol\" char(255) NOT NULL NOT NULL,\n  \"target_url_domain\" char(255) NOT NULL NOT NULL,\n  \"target_url_path\" char(255) NOT NULL NOT NULL,\n  \"created_at\" timestamp without time zone NOT NULL NOT NULL,\n  \"expired_at\" timestamp without time zone NOT NULL NULL,\n  \"deleted_at\" timestamp without time zone NOT NULL\n)\n" rows_affected=0 rows_returned=0 elapsed=1.81815ms elapsed_secs=0.00181815
Execution Error: error returned from database: conflicting NULL/NOT NULL declarations for column "expired_at" of table "url_mapping"
Fail to run migration

NOT NULL NULL appears simultaneously in the ddl statement

Reproducible Example

https://github.com/ou-bing/seaorm_null_err

Versions

sea-orm-cli 1.1.0
sea-orm-migration 1.1.0
rustc 1.81.0

postgres 17

@ou-bing
Copy link
Author

ou-bing commented Oct 16, 2024

When using SQLite, it does not report errors, but it also does not take effect

@ou-bing
Copy link
Author

ou-bing commented Oct 17, 2024

Using .col(date_time_null(UrlMapping::ExpiredAt)) is the correct usage.
The .null() method is highly misleading.

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