Entity/field definitions fix

Created on 28 August 2023, about 1 year ago
Updated 7 February 2024, 10 months ago

We migrated from V3 -> 4 -> 4dev. All upgrades were successful. However we now get the

Entity/field definitions
Mismatched entity and/or field definitions
The following changes were detected in the entity type and field definitions.

To resolve the issue we tried using Dev Tools Entity Update but it failed with the following error:

In SqlContentEntityStorageSchema.php line 1756:
The SQL storage cannot change the schema for an existing field (field_datetime in node entity) with data.

What is the more desired way to fix this please?

Drupal 10.1.2
PHP 8.2.9
0.5.22-MariaDB
nginx/1.21.6
πŸ’¬ Support request
Status

Active

Version

4.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States glynster

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @glynster
  • πŸ‡¨πŸ‡¦Canada mandclu

    Did you run drush updb after updating?

  • πŸ‡¨πŸ‡¦Canada mandclu

    Also the first error message makes it sound like it listed the changes that were detected. If you could include those, that would be helpful.

  • πŸ‡ΊπŸ‡ΈUnited States glynster

    Hey @mandclu, thank you for responding.
    Yes, we also executed the command `drush updb`, and we observed the required update, which ran successfully.

    The initial error is the one displayed on the Drupal Status Page.

    The second error occurs when we run the command `drush entity-updates`, which typically resolves the problem. Is there anything else I can include in Devel to generate more informative error messages?

  • πŸ‡¨πŸ‡¦Canada mandclu

    Apologies, I don't think I explained myself very well. The first error in the issue summary ends with this line:
    The following changes were detected in the entity type and field definitions.

    I assume that the error listed detected changes below that. Could you add those in?

  • πŸ‡¨πŸ‡¦Canada chrisck Vancouver, BC πŸ‡¨πŸ‡¦

    Just reporting that we're seeing the same error in the Status page. Not 100% sure when exactly this happened, but could be due to an update.

    Mismatched entity and/or field definitions
    The following changes were detected in the entity type and field definitions.

    Content
    The node.field_event_datetime field needs to be updated.

  • πŸ‡ΊπŸ‡ΈUnited States glynster

    @mandclu sorry you are right but that is due to another entity mis-match issue related to the media module!

    The node.field_image_media field needs to be updated.

    So at this time is there anything else I can supply that might be helpful.

  • πŸ‡¨πŸ‡¦Canada mandclu

    Would either of you be able to tell me what version of Smart Date you originally installed? You could probably find it in a git blame on your composer.json

  • πŸ‡ΊπŸ‡ΈUnited States glynster

    This project goes back to 2019.

    "name": "drupal/smart_date",
                "version": "3.1.0",
                "source": {
                    "type": "git",
                    "url": "https://git.drupalcode.org/project/smart_date.git",
                    "reference": "3.1.0"
                },
    

    Is that what you need?

  • πŸ‡¨πŸ‡¦Canada mandclu

    Yes, that is the information I was after. Thanks for that. If you look in the database at your field_datetime table, what column is it using for value and end_value?

  • πŸ‡ΊπŸ‡ΈUnited States glynster

    Here is a screenshot with all the table info.

  • πŸ‡¨πŸ‡¦Canada mandclu

    Interesting. The schema update I know of (moving the value fields to bigint) look like they have applied as expected. It may take some digging to figure out the perceived differences

  • πŸ‡ΊπŸ‡ΈUnited States glynster

    Right, makes sense as the update did perform without a failure. If you need me to run any tests let me know.

    I do have another website on Smart Date 4.0.3 which I can test on upgrading to 4.1.0-rc2. I am pretty sure that site was using the same base as this example.

  • πŸ‡¨πŸ‡¦Canada chrisck Vancouver, BC πŸ‡¨πŸ‡¦

    We first installed Smart Date 3.5.0, and then four weeks ago upgraded to 4.1.0-beta1. We've been keeping up with regular updates.

  • πŸ‡ΊπŸ‡ΈUnited States glynster

    Interesting I cannot run the cron and get this:

    The website encountered an unexpected error. Please try again later.
    
    Error: Call to a member function getColumns() on bool in Drupal\Core\Entity\Query\Sql\Tables->addField() (line 246 of core/lib/Drupal/Core/Entity/Query/Sql/Tables.php).
    Drupal\Core\Entity\Query\Sql\Condition->compile(Object) (Line: 176)
    Drupal\Core\Entity\Query\Sql\Query->compile() (Line: 81)
    Drupal\Core\Entity\Query\Sql\Query->execute() (Line: 285)
    Drupal\smart_date_recur\Entity\SmartDateRule->getParentEntity(1) (Line: 786)
    smart_date_recur_cron() (Line: 335)

    Perhaps this is what helps us solve the issue?

  • πŸ‡ΊπŸ‡ΈUnited States glynster

    @mandclu is there anything else I can help with on this?

  • πŸ‡ΊπŸ‡ΈUnited States glynster

    Some updates for you:

    • To get the cron working again I have to delete the recurring instances. Luckily this was a site where all past events had been and gone and were no longer published. Then the cron ran without issue.
    • We then deleted the field_datetime smart date field and added it back using the same machine name, cleared caches and this resolved the Mismatch issue. Not ideal as it wipes out all the dates.
    • We were then able to do a drush cex and push this to live.

    Not an ideal situation unless you can remove the data.

    We also tried to save the storage settings for the field but would always get the same error message:

    The SQL storage cannot change the schema for an existing field (field_datetime in node entity) with data.

  • πŸ‡§πŸ‡ͺBelgium bramvandenbulcke

    I'm in the same situation.

    The error started showing on two installs after upgrading from 4.0.x to 4.1.x. This had one db update (increase_column_storage): this update applied cleanly. On one install, in development phase, I could remove the field and add it again. Another install has already more than 1000 nodes, so this one will be more tricky. I guess the client won't notice, as everything is still functioning as before. The installation in development phase has one language, the other is multilingual. Both installs use the same field (field_date) on two content types.

    Errors:

    • Status report: Mismatched entity and/or field definitions. The following changes were detected in the entity type and field definitions. Content: The node.field_date field needs to be updated.
    • When trying to resave the field: An error occurred while saving the field: The SQL storage cannot change the schema for an existing field (field_date in node entity) with data.

    I also add the schema info.

  • πŸ‡§πŸ‡ͺBelgium bramvandenbulcke

    Also adding the schema from phpMyAdmin.

  • πŸ‡¨πŸ‡¦Canada mandclu

    I'm tempted to close this issue as a duplicate of πŸ› node.field_[name] field needs to be updated Needs review but there's been some good discussion in here, so I'll hold off for now. That issue does have a patch, and links to the core issues with a patch available (you only need the patch from one) that allow the stored schemas to be updated to match the updated database structure.

    Theoretically another possible approach would be: create a new Smart Date field, and migrate the existing data into the new field using Smart Date's drush command. Then, delete and re-add the original field, and migrate the data back. After validating that everything is working as intended, delete the interim field. The biggest problem with this workaround is that I'm not sure the drush command was designed to copy over recurring information, so it might need an updated to be up to the task.

    Ultimately my preference would be to get ✨ Provide a flag to allow updates to stored schema for fields Fixed committed, which requires finishing the associated test. With that in core, we could commit πŸ› node.field_[name] field needs to be updated Needs review and get these schema update issues properly resolved.

  • πŸ‡§πŸ‡ͺBelgium bramvandenbulcke

    Thanks for linking the other issues!

    The module smart_date_recur is not installed in my case.

  • πŸ‡¨πŸ‡¦Canada mandclu

    Apologies for the confusion. The fix in that issue applies to the main Smart Date module, not smart_date_recur. I have updated that issue's metadata to reduce confusion.

  • πŸ‡ΊπŸ‡ΈUnited States glynster

    @mandclu just wanted to give you some feedback.

    As our setup was from 2019, we had many nodes. We applied the 2 proposed patches:

    ✨ Provide a flag to allow updates to stored schema for fields Fixed
    πŸ› node.field_[name] field needs to be updated Needs review

    And this resolved the problem, allowing the schema to fully update and keep all the data intact. Super easy and a huge help!

Production build 0.71.5 2024