After the 'type' field was removed in #2621674: Add APIs for easier access to media type plugins to the entity class, I started to get the following error in the status report:
Mismatched entity and/or field definitions
The following changes were detected in the entity type and field definitions.Media
Delete the Type field.
The same problem will be faced by anyone updating from beta1 to follow-up versions.
I traced it to the fact that there is still an entry in my database key_value table with the serialized "type" field in the entry for collection = "entity.definitions.installed" and name = "media.field_storage_definitions".
I attempted to delete it from this DB record, and to alter the media_field_data and media_field_revision to remove the obsolete "type", but this only leads to a WSOD in the status report.. Would it be possible to add a hook_update_N() to delete that field properly?
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | 2652420_15.patch | 552 bytes | slashrsm |
| #9 | 2652420_8.patch | 557 bytes | slashrsm |
| #4 | 2652420_4.patch | 790 bytes | slashrsm |
Comments
Comment #2
slashrsm commentedCore automatically handles changes in entity base fields. No need for modules to handle this manually.
drush entity-updatesshould do the job.Comment #3
berdirNo, it doesn't. Modules are expected to do this explicitly. It just provides the API.
See https://www.drupal.org/node/2554097
drush entity-updates should work, but you can't expect everyone to be able to use that.
Comment #4
slashrsm commentedMeh... slightly older change record confused me. Here we go.
Comment #5
berdirLooks good to me.
Comment #6
slashrsm commentedCommitted. Thanks!
Comment #8
bigbaldy commentedI ran into a problem with updating from the previous dev version. Error message below. I resolved it by 1) drush dl media_entity (to install the beta version). 2) drush entup (re-installs the type field) . 3) drush media_entity --dev. 4) drush updb.
An AJAX HTTP error occurred.
HTTP Result Code: 200
Debugging information follows.
Path: /update.php/start?id=63&op=do_nojs&op=do
StatusText: OK
ResponseText: Recoverable fatal error: Argument 1 passed to Drupal\Core\Entity\EntityDefinitionUpdateManager::uninstallFieldStorageDefinition() must implement interface Drupal\Core\Field\FieldStorageDefinitionInterface, null given, called in /var/www/john/d8/k9agility/drupal/modules/media_entity/media_entity.install on line 22 and defined in Drupal\Core\Entity\EntityDefinitionUpdateManager->uninstallFieldStorageDefinition() (line 198 of /var/www/john/d8/k9agility/drupal/core/lib/Drupal/Core/Entity/EntityDefinitionUpdateManager.php).
Comment #9
slashrsm commentedIf I do:
- Install site
- Download media_entity beta 1
- Install it
- Update it to 8.x-1.x
- Run database updates
This works and removes type field.
I suspect something (entup?) removed type field before the update hook was run. This patch should make it a bit more robust.
Comment #10
bigbaldy commentedI tried to duplicate the problem by reinstalling media_entity from the most recent dev version with the type field and with the most recent dev without the type field. I then tried updating to the most recent dev. In all cases I was not able to reproduce the problem I reported. As you suggest I suspect that drush entity-update fixed an unresolved update in my database. drush entity-update was a command that I had overlooked until I read this issue. Thanks for the help. Not sure how to test the patch without being able to replicate the problem.
Comment #11
berdirYou should be able to reproduce by installing the previous version, run drush entity-updates and afterwards run drush updb.
Sorry for missing this, looks like the correct fix for me.
Comment #12
slashrsm commentedSorry for causing this in the first place.
Comment #14
JamesK commentedThis update function still fails when updating beta1 sites that have existing media entities. Here's the error from drush updb:
Failed: Unable to delete a field (type in media entity) with data that cannot be purged.Is there any workaround for this?
Comment #15
slashrsm commentedThis should work.
Comment #16
JamesK commentedPerfect!
Comment #17
JamesK commentedComment #18
slashrsm commentedCommitted.