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.
When upgrading to 7.x-1.2 I get the following error during updb:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'engagement_score' cannot be null
Performed update: redhen_engagement_update_7101
The problem lies in the UPDATE statement:
UPDATE redhen_contact rc SET engagement_score = (SELECT SUM(score) FROM redhen_engagement re JOIN redhen_engagement_score res on re.engagement_score = res.name WHERE re.contact_id = rc.contact_id)
The inner select return NULL if there is no engagements logged for a contact. Locally I've solved this by adding an COALESCE(…, 0) around the inner select.
The statement takes a long time for larger databases (perhaps due to the inner select). Maybe it's better to use a JOIN and avoid NULL values altogether.
Comment | File | Size | Author |
---|---|---|---|
#2 | 0001-Use-COALESCE-in-7101.patch | 1.34 KB | torotil |
#1 | redhen_engagement_integrity_constraint_7101.patch | 863 bytes | torotil |
Comments
Comment #1
torotil CreditAttribution: torotil commentedI've found a rather dumb reason for the performance issues (in my drupal setup).
Here's a patch that fixes this bug by introducing COALESCE().
Comment #2
torotil CreditAttribution: torotil commentedHere is a patch that makes it possible to rerun the failed (perhaps due to this bug) update hook.
Comment #3
alicemoon CreditAttribution: alicemoon commentedthanks torotil - I had the same problem and your patch allowed my site to update properly.
Comment #4
levelos CreditAttribution: levelos commentedThanks torotil, committed in 832217f.