Skip to content

Cannot set column to nullable #2396

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

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

Cannot set column to nullable #2396

ou-bing opened this issue Oct 16, 2024 · 4 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.

@YenHarvey
Copy link

I've also encountered this issue. Have you found a version without this bug? I'm using PostgreSQL 16 and sea-orm-migration 1.1.7. All data fields default to NOT NULL, and if I force them to NULL, conflicts occur.

@YenHarvey
Copy link

I understand your point now, thank you so much! This behavior is quite counterintuitive and opposite to database conventions. By default, fields are not_null, and then some fields have xx_null or xx_nulq, and you can also use .null(). I can't imagine how long it would take to find the problem without auto-completion.

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

2 participants