-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Primary key should be NOT NULL
#23622
Conversation
r? @schneems (@rails-bot has picked a reviewer for you, use r? to override) |
af583a8
to
2c91c68
Compare
Given that this only affects SQLite, I would prefer an implementation that only touches SQLite related code. Is there a reason we can't just emit |
This change is also needed for #23553. Should we affect only sqlite3 and mysql2 adapters? |
Why would this affect the mysql2 adapter? I thought primary keys were implicitly not null in mysql? |
AR's column definition is default nullable. But the native timestamp type in MySQL is default not null.
|
2c91c68
to
0faa08b
Compare
|
||
def column_options(o) | ||
options = super | ||
options[:null] = false if o.primary_key |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed to only affect to SQLite, thanks!
r? @sgrif |
5bc47b2
to
23f6452
Compare
@@ -229,7 +229,7 @@ def test_any_type_primary_key | |||
assert_equal "code", Barcode.primary_key | |||
|
|||
column = Barcode.column_for_attribute(Barcode.primary_key) | |||
assert_not column.null unless current_adapter?(:SQLite3Adapter) | |||
assert_not column.null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the test first at #23959.
This PR fixes the wrong behavior for sqlite3 adapter.
62b3e49
to
0ea47eb
Compare
@rafaelfranca What do you think about this? |
Follow up to rails#18228. In MySQL and PostgreSQL, primary key is to be `NOT NULL` implicitly. But in SQLite it must be specified `NOT NULL` explicitly.
0ea47eb
to
98fb374
Compare
@jeremy What do you think about this? |
Primary key should be `NOT NULL`
Follow up to #18228.
In MySQL and PostgreSQL, primary key is to be
NOT NULL
implicitly.But in SQLite it must be specified
NOT NULL
explicitly.lib/active_record/connection_adapters/sqlite3_adapter.rb#L56