Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Part of #2616488: [meta] MySQL 5.7 / MariaDb 10.1.* support.
MySQL < 5.7 silently corrects tables to have a NOT NULL primary key if it's specified as NOT NULL => FALSE.
5.7 throws an error.
We should consider throwing a helpful exception ourselves before attempting to create the table, so that people write code compatible with older versions of MySQL.
Proposed resolution
Check the primary key and ensure all columns have NOT NULL definitions.
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#20 | interdiff-20.txt | 3.84 KB | amateescu |
#20 | 2616724-20.patch | 14.9 KB | amateescu |
Comments
Comment #2
catchComment #3
effulgentsia CreditAttribution: effulgentsia at Acquia commentedComment #5
daffie CreditAttribution: daffie commentedMost if not all primary keys are of the serial type. Does anybody know if there are primary keys that are not of the serial type?
Comment #6
chx CreditAttribution: chx at Smartsheet commentedEdited: deleted. This was solely an api.drupal.org link but I have confidence in the good developers of Drupal core that they would find a way to get insulted even by that so I deleted it.
Comment #11
daffie CreditAttribution: daffie commentedThis patch should fix the testbot fail for the new MySQL 5.7 environment.
Comment #12
daffie CreditAttribution: daffie commentedSecond try.
Comment #13
daffie CreditAttribution: daffie commentedThird try.
Comment #14
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedI've been working on this as well from the angle of the initial scope, which is to throw our own db schema exception when a user tries to define a primary key without
'not null' => TRUE
.The "fail" patch shows the new exception being thrown, and the "pass" one includes the fixes from #13 :)
Comment #15
daffie CreditAttribution: daffie commented@amateescu: I like your idea with the added method to make sure that every primary key does have a allows null value. What I miss is tests where the thrown exception is caught.
Comment #16
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThe new exception is not meant to be caught by default, it's simply there to provide a friendlier message to module authors :)
Comment #18
daffie CreditAttribution: daffie commentedComment #19
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThis should fix the sqlite driver by making its schema introspection return the proper 'not null' status of a field if it's part of the primary key.
Comment #20
amateescu CreditAttribution: amateescu for Pfizer, Inc. commented@daffie, sorry, I didn't understand your request from #15 at first read :/ Here's full test coverage for the exception, which already caught a bug in the pgsql implementation.
Comment #21
daffie CreditAttribution: daffie commentedYou have made the same changes as I did to the SchemaTest class to fix the problem for MySQL 5.7.
I like your idea for throwing exception when a primary key field does not have the is not null option set.
You have added the by me requested tests.
I all looks good now to me.
For me it is RTBC.
Great work @amateescu.
Comment #23
catchCommitted 72cd973 and pushed to 8.6.x. Thanks!