Problem/Motivation
Hi, I get:
Mismatched entity and/or field definitions
The following changes were detected in the entity type and field definitions.
Stock location
The User ID field needs to be installed.
after updating the commerce_stock dev module.
As far as I can see, this is due to the change of the StockLocation Entity:
commerce_stock/modules/local_storage/src/Entity/StockLocation.php
We see the new entity_key owner = uid here:
* entity_keys = {
* "id" = "location_id",
* "bundle" = "type",
* "label" = "name",
* "uuid" = "uuid",
* "langcode" = "langcode",
* "status" = "status",
* "owner" = "uid",
* },
Steps to reproduce
Update the module from a version without the uid field to a version with the uid field
Proposed resolution
Update the entity definition table via an update hook
Data model changes
There should be a uid field in the table commerce_stock_location_field_data
Best, Lars
Comments
Comment #2
jrochate commentedSame situation here.
But I have created the uid fields on commerce_stock_location and also commerce_stock_location_field_data but the message kept on report.
And also added user 1 to both fields, resaved Stock UI settings, but nothing changed.
Comment #3
jrochate commentedAnyway, if you run:
drush entity-updatesthe uid field will be created and the problem is solved :)
Comment #4
guy_schneerson commentedMy understanding of Drupal release types is that Alpha versions do not require update hooks for schema changes. If like @jrochate suggests "drush entity-updates" solves this then it sounds like you can easily get around this issue.
In any case, if a patch is offered I will be happy to review it.
Comment #5
gkaas commentedSame issue here, but
drush entity-updatesreturns the following message in our case:Comment #6
jrochate commentedUse this module:
https://www.drupal.org/project/devel_entity_updates
Comment #7
gkaas commentedThanks @jrochate! However, the Devel Entity Updates module page states:
Comment #8
jrochate commentedAlways backup as precaution.
Then install and run the drush command.
Check that mysql tables identified above now has the correct fields.
Check if everything works.
You're done.
if not, restore.
Comment #9
artis commentedFrom the change record which removed 'drush entup':
We need to write an update function for this change and push a new release to properly fix this issue.
Comment #10
guy_schneerson commentedJust to confirm this is likely to be related to the change in StockLocation.php where
was added to the entity_keys.
If a patch is submitted I will commit it. In the meantime, if you have this issue you should be able to use "Devel Entity Updates" to fix this.
Comment #11
harcher commentedI am also having this issue now after updating to alpha6.
As #7 mentions above, Devel Entity Updates module page states not to use for fixing Mismatched entities.
Is it safe to fix with Devel Entity?
Comment #12
renrhafSame here
Comment #13
agoradesign commentedYou can implement an update hook in a custom module like this:
Comment #14
nathaniel commentedAttached a patch that adds modules/local_storage/commerce_stock_local.post_update.php.
Note that the default uid for existing {commerce_stock_location_field_data}.uid will be NULL (0 after edit).
Comment #15
nathaniel commentedErr, @agoradesign is correct this should be in hook_update_N() then I guess the data could be updated in post_update if needed.
Comment #16
jrochate commented@nathaniel what about people that solved this using drush entity-updates. Does this script colide with those with the problem fixed, or the script will simply ignore and move on?
thanks.
Comment #17
nathaniel commentedLooks like it will ignore and move on. Ran it a few times on a test site with no issues. I'm hesitant to write a patch for a hook_update_N script though since that could cause issues for someone if it isn't committed and the same number is used later on for something else. Adding it to a custom module worked fine for me.
Comment #18
agoradesign commentedI'm sure there's a possibility to check the field existence before actually trying to create it. And Nathanial is fully right: I would not recommend to anyone to use a patch including an update hook, if it can be avoided easily. If the maintainer decides to commit the update hook, he has to take care anyway to check the case, if the field already exists (because not only the custom updated installations already have the field, also new installations)
Comment #19
renrhafHere is a patch that adds an update hook.
If the field is already created, the update hook won't perform any action.
Tested with and without the field installed.
Comment #20
renrhafOoops patch rerolled for 8.x-1.x
Comment #21
harcher commentedThanks @Renrhaf, patch #20 works on alpha6.
Comment #22
guy_schneerson commentedI have moved the update hook to the local_storage module as it creates the entity that is updated in the hook.
I only tested with the field installed but as others have tested I am happy to commit this
Comment #24
guy_schneerson commentedThanks to everyone for their contribution. Marking as fixed but do reopen if any issues.
Comment #25
mitrpaka commentedWas not able to run update hook of 8006 successfully due to missing imports of BaseFieldDefinition and TranslatableMarkup classes.
New patch files attached:
- commerce_stock-fix-uid-missing-3211778-22.patch - Full patch file (including committed code to 8.x-1.x) to apply on top of 8.x-1.0-alpha6 version.
- commerce_stock-fix-uid-missing-3211778-22-updates-only.patch (including only changes after latest commit to 8.x-1.x)
Comment #26
melpers commentedThanks - commerce_stock-fix-uid-missing-3211778-22.patch worked for me applied to 8.x-1.0-alpha6.
Comment #27
j. commentedWhen i tried the patch in #22, I also hit the same issues described in #25. I'm on 8.x-1.0-alpha6 and have not performed any entity updates.
commerce_stock-fix-uid-missing-3211778-22.patch worked for me.
Comment #28
crizI also can confirm that with latest alpha version the updates from #25 are necessary so that update hook 8006 runs through.
Comment #29
jdcllns commentedI'm sorry but I'm lost. I'm using 8.x-1.0-alpha6. Which patch do I apply to clear up the User ID field error message?
Comment #30
vikramy commentedjdcllns -- use this commerce_stock-fix-uid-missing-3211778-22.patch
+1 for this commit.
Comment #32
guy_schneerson commentedThanks @mitrpaka
I have added both missing classes to the use section, so the dev version should work now.