Problem/Motivation
Database schema field type changes for existing fields with existing data fail for method call updateFieldStorageDefinition() from iframe_update_8101() and iframe_update_8201() update hooks.
Update started: iframe_update_8201
[error] The SQL storage cannot change the schema for an existing field (field_xx in entity) with data.
Proposed resolution
- Temporarily store the field data to a variable, wipe the data from the database table, change the storage type and restore the field data.
-
There is already a helper method
FieldTypeUpdateUtil::_field_type_schema_column_spec_change_helper()that comes in hand with this module and it can be used in the update hooks.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | interdiff_7-9.txt | 397 bytes | fathima.asmat |
| #9 | update-n-hook-fail-3312090-9.patch | 1.22 KB | fathima.asmat |
| #2 | update-n-hook-fail-3312090-2.patch | 1.04 KB | fathima.asmat |
Comments
Comment #2
fathima.asmat commentedA patch is attached.
Comment #3
fathima.asmat commentedComment #4
nguyenphanI apply update-n-hook-fail-3312090-2.patch it is fine when update.
Comment #6
neffets commented8.x-2.19 fixes the update hooks, thx for the info
Comment #7
fathima.asmat commentedThe recent commit merged to the code has also removed the code of adding new columns such as header level to the database table, hence is causing another updb issue unfortunately.
See commit removal- https://git.drupalcode.org/project/iframe/-/commit/b9ea596a7c920b6bdb978....
https://git.drupalcode.org/project/iframe/-/commit/b9ea596a7c920b6bdb978...
I have attached a patch below that adds the fields to the schema as part of the helper method that updates the storage definitions for the altered columns.
Comment #8
fathima.asmat commentedComment #9
fathima.asmat commentedPatch 7 was missing a closing brace, this patch should resolve that.
Comment #11
neffets commentedOK.
I added Patch-9 but changed the position in Code.
If get old code with fewer columns and then add the new-ones, it could be that the old-data cannot be imported because of not-null-missing-data-for-column errors.
So I changed the position to
* table => first add the new columns (so any defaults will be filled in)
* then get-old-data
* then wipe
* at end fill in the exported data (with all known columns) to the empty tables.
Comment #12
neffets commentedSchema update improved to allow adding new columns for empty tables too in file src/FieldTypeUpdateUtil.php, (see issue #2843108 and issue #937442 too)
Comment #13
neffets commented