0

I am working on a project with custom entity type. My module works fine in my local environment. But when I deployed to my staging site, things are strange.

For instance, I tried to change my entity definition and then run the drush command:

drush entity:updates -y

The command gave me positive response:

The following updates are pending:

dharmasun_payment entity type : 
The Field 1 field needs to be installed.
The Field 2 field needs to be installed.

 // Do you wish to run all pending updates?: yes.

 Finished performing updates

Except the database was not changed at all. So when I re-run the command, it gives me the exact same output.

The staging site might have some different module installed than my development environment. But I cannot make breaking change on the staging platform (or my workmates would be mad).

My questions:

  1. How do I begin to debug this? Is there anyway I can get better log messages with the drush entity:update command?
  2. Or is there any alternative way to update entity definition and make changes to database?

Thanks.

2

For deploying entity schema updates use an update hook and the entity definition update manager. See the release note of Drupal 8.7.0 and the change record Support for automatic entity updates has been removed.

drush entup is moving from core to contrib: https://www.drupal.org/project/devel_entity_updates

This project aims to restore this functionality as a developer-only tool. This module depends on Devel and is not meant to be enabled in production environments or relied upon in deployment workflows.


"Or is there any alternative way to update entity definition and make changes to database?"

Yes, there is. Don't use base fields other than for the very basic things that never change (if core makes changes necessary you'll probably find then examples how to write the update hook). Instead use configurable fields (bundle fields), so that you can deploy easily through configuration.

  • I tried the hook_update_N with entity_definition_update_manager approach. The update ran on a drush updatedb command, but the database table was not updated at all. No error. Any idea how I can debug this? – Koala Yeung May 15 at 8:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.