A simple quick drupal 8.4 installed from drush, with the media_entity_image module and a single media bundle "image" with two fields "caption" and "image file" fails to upgrade to core media after upgrading to the media_entity 2.x branch. The "Revisionability" of the media bundle seems not to have an impact on whether the upgrade fails (it always fails).

drush updb
The following updates are pending:

media_entity module : 
  8200 -   Clears the module handler's hook implementation cache. 
  8201 -   Replace Media Entity with Media. 

Do you wish to run all pending updates? (y/n): y
Performing media_entity_update_8200                                          [ok]
SQLSTATE[HY000]: General error: 1 no such column: revision_uid: CREATE INDEX [error]
main.media_revision_0_media_field__revision_uid__target_id ON
media_revision_0 (revision_uid); Array
(
)

Performing media_entity_update_8201                                          [ok]
Failed: SQLSTATE[HY000]: General error: 1 no such column: revision_uid:      [error]
CREATE INDEX main.media_revision_0_media_field__revision_uid__target_id ON
media_revision_0 (revision_uid); Array
(
)

Cache rebuild complete.                                  

afterwards adding media seems to be broken media/add/image

and running the updb again falls into the case trying to catch other weird contrib modules called "media" -- likely confused by core's media being active now...

$ drush updb
In order to run the Media Entity 2.x upgrade, please uninstall and remove from the codebase the contributed "Media" module.

Comments

yareckon created an issue. See original summary.

yareckon’s picture

Issue summary: View changes
marcoscano’s picture

yareckon’s picture

Title: Media Entity upgrade -> core fails on absent column revision_udi » Media Entity upgrade -> core fails on absent column revision_uid
phenaproxima’s picture

Status: Active » Needs review
Issue tags: +Media Initiative
StatusFileSize
new1.69 KB

Does this patch help?

phenaproxima’s picture

Priority: Major » Critical

Bumping this to Critical priority, because it is an update path bug.

yareckon’s picture

Hi @phenaproxima, thank you for your work on this and your amazingly quick response. Unfortunately I have to report the identical error is still occuring after patching the 2.x branch before drush updb. Hopefully that is what should be patched.

This is after:

  1. setting up the site the same as above (installing media entity image 1.x, creating bundle image, creating one media entity with binary jpg and caption).
  2. changing to media 2.x branch, applying your patch over it
  3. then running updb

The error is identical. Could it be that I should run things in a different order, or is your patch against media_entity 1.x?

phenaproxima’s picture

Status: Needs review » Needs work

If it didn’t work for you, it behooves me to figure out what went wrong, and fix it. Thanks for testing, @yareckon!

yareckon’s picture

One additional data point: I am starting my test site on drupal 8.4, not upgrading an actual 8.3 site, in case that makes any difference at all.

phenaproxima’s picture

Status: Needs work » Postponed (maintainer needs more info)

I have been unable to reproduce this locally. Here's what I did:

  1. Installed Drupal 8.4.0, standard profile, in a MySQL database.
  2. Installed Media Entity -- 8.x-1.x HEAD.
  3. Created an 'image' media type, with an image field. I didn't bother with a caption field.
  4. Added a media item of the 'image' type.
  5. Switched to the 8.x-2.x branch of Media Entity and installed the proper dependencies (like media_entity_generic) to get the update path to run.
  6. Applied patch #5 to Media Entity.
  7. Ran drush updb, using Drush 9.

Under these circumstances, the update ran without flaw. Is there anything about these steps, apart from the lack of a caption field (which, to be honest, I can't imagine breaking the update path) that don't square with yours?

yareckon’s picture

Hi @phenaproxima, I share your skepticism that the caption field plays a role.
I will try to reproduce using your recipe. The most obvious difference has been that I had used drush qd, which is sqlite.
Maybe this is the head slapping moment, but I didn't have media_entity_generic installed unless that gets pulled in automatically via a composer update to the 2.x branch.

kylebrowning’s picture

Status: Postponed (maintainer needs more info) » Active

I am also experiencing this error.

Trying to update to 8.4.2 from 8.4.0.

media_entity module

Update #8201

Failed: Drupal\Core\Database\SchemaObjectDoesNotExistException: Cannot change the definition of field media_revision.revision_uid: field doesn't exist. in Drupal\Core\Database\Driver\mysql\Schema->changeField() (line 577 of /var/www/docroot/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php

This may have something to do with lightning but im guessing not.

berdir’s picture

I'm also seeing this, thought it was because I'm not switching from media_entity to media as part of the 8.4.x update, but not sure anymore now as you do seem to have tested exactly that. You did however install media_entity on a site that was *installed* as 8.4.0 if I understand correctly.

Can you try installing 8.3.7, install media_entity 1.x, then updating to 8.4, then switch to media? I'll continue testing as well, but it's late sunday night :)

cman9090’s picture

+1 seeing same issue, website dead.

marcoscano’s picture

@kylebrowning, @cman9090,
could you please share more details of your installations, or ideally steps to reproduce the error?

I have myself also tried to reproduce this without luck, in my case using Drupal 8.5.x-dev, installing ME 1.x, then upgrading to ME 2.x, and everything works as expected in this case...

(Note: while testing please also make sure you use the latest Mecia Entity 8.x-2.x-dev version, because it is in active development and some recent fixes were included)

cman9090’s picture

8.3.7 upgrade to 8.4.2. Had Media 1.x installed, did everything it said in instructions to upgrade. Got the error on this bug.

marcoscano’s picture

OK so I could finally test this also with the core upgrade as well (sorry for being skeptical before...)

Steps I performed:
- Drupal 8.3.7 + Media Entity 8.x-1.6 + Media Entity Image 8.x-1.2
- Image bundle (called image), with an image source field called field_image
- Created media items of this type
- Upgraded core to 8.4.2, ran core DB updates with drush updb
- Upgraded to Media Entity 2.x HEAD (and added the additional required modules to the codebase)
- Ran drush cr, drush mecu and then drush updb

No errors still... :(

@cman9090,
Anything I'm doing differently from you when you have the issue?

Thanks!

eric.guerin@ucsf.edu’s picture

I am also experiencing this issue, any guidelines on how to fix would be appreciated. The patch was already included in my codebase, however still getting the following errors.

[notice] Executing media_entity_update_8201
[error]  Cannot change the definition of field media_revision.revision_uid: field doesn't exist. 

After this no updatedb is completed. I am on Drupal version 8.4.4 here or at least trying to be.

eric.guerin@ucsf.edu’s picture

StatusFileSize
new1.97 KB

I have added a patch that seems to work for me, it seems like the table column names were already changed through some other process, so this is just a way to double check that those columns aren't there or ignore them if they are.

Calling this the 2918172-6-8.4.4.patch. Since it probably only applies to later version of Drupal 8.4. FYI this patch does not contain the original patch code, you would want to run both if necessary.

btully’s picture

Thanks for the patch @gr8tkicks. It worked somewhat, in that I'm no longer seeing the dreaded

[error]  Cannot change the definition of field media_revision.revision_uid: field doesn't exist. 

However, now I am seeing the following error:

 [error]  SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'media.type.image' for key 'PRIMARY': UPDATE {config} SET name=:db_update_placeholder_0
WHERE (name = :db_condition_placeholder_0) AND (collection = :db_condition_placeholder_1); Array
(
    [:db_update_placeholder_0] => media.type.image
    [:db_condition_placeholder_0] => media_entity.bundle.image
    [:db_condition_placeholder_1] =>
)

 [error]  Update failed: media_entity_update_8201

Does this mean one needs to manually go into the DB config table and delete the `media.type.image` row?

When comparing values for media.type.image and media_entity_bundle.image it looks as though they differ significantly:

media.type.image

a:13:{s:4:"uuid";s:36:"683f10db-7dea-4f08-b09e-ec9bb890c429";s:8:"langcode";s:2:"en";s:6:"status";b:1;s:12:"dependencies";a:0:{}s:5:"_core";a:1:{s:19:"default_config_hash";s:43:"u7OxrscEED35iDR3R0akmw7QNvBSMEPJXFtKP57qBh8";}s:2:"id";s:5:"image";s:5:"label";s:5:"Image";s:11:"description";s:36:"Use local images for reusable media.";s:6:"source";s:5:"image";s:25:"queue_thumbnail_downloads";b:0;s:12:"new_revision";b:1;s:20:"source_configuration";a:1:{s:12:"source_field";s:17:"field_media_image";}s:9:"field_map";a:0:{}}

VS.

media_entity_bundle.image

a:13:{s:4:"uuid";s:36:"5bfd1ed0-70ea-4d0b-8793-d690e63e5f20";s:8:"langcode";s:3:"und";s:6:"status";b:1;s:12:"dependencies";a:1:{s:6:"module";a:1:{i:0;s:5:"media";}}s:5:"_core";a:1:{s:19:"default_config_hash";s:43:"-L1iQMNQszdvp0XZx3HA7uzKBmU7ccdXh3kHCKtVFQs";}s:2:"id";s:5:"image";s:5:"label";s:5:"Image";s:11:"description";s:22:"Locally hosted images.";s:4:"type";s:5:"image";s:25:"queue_thumbnail_downloads";b:0;s:12:"new_revision";b:0;s:18:"type_configuration";a:2:{s:12:"source_field";s:5:"image";s:11:"gather_exif";b:0;}s:9:"field_map";a:0:{}}

Note that media.type.image uses a source_field of "field_media_image" whereas media_entity_bundle.image uses a source_field of "image" (in addition to other differences). So not sure how to get by this one. Any ideas?

Is Media Entity just not compatible with D8.44+ ?

btully’s picture

confirmed that patch from #19 works once you delete the media.type.image row from the config table (if it already exists) if you see the Integrity constraint violation: 1062 Duplicate entry 'media.type.image' for key 'PRIMARY':... error.

g_miric’s picture

I'm also getting the "[error] SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'media.type.image'... " when I try to exexcute updates.

Ralf Eisler’s picture

I have the same error updating from 8.4.0 / 2.2.0 to 8.4.5 / 2.2.1 or 2.2.2 or 2.2.3.
The above patches ar already applied to my codebase or refused (2918172-6-8.4.4.patch).

benstallings’s picture

I am having this error when attempting the upgrade in Drupal 8.5.1. I haven't attempted the patches yet; just updating this thread to say that 8.5.1 is among the Drupal versions affected.

jasonlttl’s picture

I don't know exactly what is going on here, but this may help.

In my dev drupal instance, which uses sqlite, this statement fails because there is an index that refers to the column revision_uid and the sqlite driver is not smart enough to update it.

function media_entity_update_8201() {
   ...snip...
  $db->changeField(
    'media_revision', 
    'revision_uid', 
    'revision_user', 
    $field_definitions['revision_user']->getColumns()[$field_definitions['revision_user']->getMainPropertyName()];
  );

When the driver renames a field like this, it essentially recreates the table with the 0 prefix (and any existing indexes) and copies all the data then swaps out the tables. Perhaps other drivers are smarter?

So for example, if I drop the index before and recreate it after, it appears to work fine through that part.

function media_entity_update_8201() {
   ...snip...
  $db->dropIndex('media_revision', 'media_field__revision_uid__target_id');
  $db->changeField(
    'media_revision', 
    'revision_uid', 
    'revision_user', 
    $field_definitions['revision_user']->getColumns()[$field_definitions['revision_user']->getMainPropertyName()];
  );
  $db->addIndex('media_revision', 'media_field__revision_uid__target_id', ['revision_user'], []);

Note, I haven't fully tested this all the way through as much later in the update I'm getting another sqlite error involving number of arguments and the cache (a pretty common sqlite problem).

benstallings’s picture

Thank you for the tip, jasonlttl -- the problem turned out to be SQLite on my local as well. When I tried another local install of the same site using MySQL, the update completed without error.

Ralf Eisler’s picture

@jasonlttl

Thank you for the tip, but my installations dont run on SQLite.

I am trying to got through the update-process to Lightning 3.1.0.1 several times now.

I found out, that following the procedure with Lightning strict was very helpful.

Despite of following update procedures, I have a persistent problem updating version >= 2.2.1.

I also found out, that 2918172-6-8.4.4.patch indeed works updating to core 8.4.2/Lightning 8.x-2.24, for solving the General error: 1 no such column: revision_uid problem.

It however reveals an other problem with Media entity audio, which the update tries to transfer to Media, which of course does not work, because it does not exist in core.

As a result, drush updatedbfails:

drush updatedb
 ----------------- ----------- --------------- --------------------------------------------------- 
  Module            Update ID   Type            Description                                        
 ----------------- ----------- --------------- --------------------------------------------------- 
  lightning_media   8018        hook_update_n   Updates the media browser's argument validation.   
  media_entity      8201        hook_update_n   Replace Media Entity with Media.                   
 ----------------- ----------- --------------- --------------------------------------------------- 

 Do you wish to run the specified pending updates? (yes/no) [yes]:
 > yes

 [notice] Update started: media_entity_update_8201
 [error]  The "audio" plugin does not exist. 
 [error]  Update failed: media_entity_update_8201 
 [error]  Update aborted by: media_entity_update_8201 
 [error]  Finished performing updates. 

Or with /update.php:

media_entity module

Update #8201

Failed: Drupal\Component\Plugin\Exception\PluginNotFoundException: The "audio" plugin does not exist. in Drupal\Core\Plugin\DefaultPluginManager->doGetDefinition() (line 52 of /home/evolisch/public_html/addon_websites/nobag.debug.design360.ch/docroot/core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php).
drush pm:list | grep media
  Lightning                         Lightning Media (lightning_media)                                                   Enabled    8.x-2.24        
  Lightning                         Bulk Media Upload (lightning_media_bulk_upload)                                     Disabled   8.x-2.24        
  Lightning                         Media Document (lightning_media_document)                                           Enabled    8.x-2.24        
  Lightning                         Media Image (lightning_media_image)                                                 Enabled    8.x-2.24        
  Lightning                         Media Instagram (lightning_media_instagram)                                         Enabled    8.x-2.24        
  Lightning                         Media Twitter (lightning_media_twitter)                                             Enabled    8.x-2.24        
  Lightning                         Media Video (lightning_media_video)                                                 Enabled    8.x-2.24        
  Core                              Media (media)                                                                       Enabled    8.4.2           
  Media                             Media entity (2.x) (media_entity)                                                   Enabled    8.x-2.0-alpha1  
  Media                             Media entity audio (media_entity_audio)                                             Enabled                    
  Media                             Media entity document (media_entity_document)                                       Disabled                   
  Media                             Media entity image (media_entity_image)                                             Disabled                   
  Media                             Media entity Instagram (media_entity_instagram)                                     Enabled    8.x-2.0-alpha1  
  Media                             Media entity Twitter (media_entity_twitter)                                         Enabled    8.x-2.0-alpha2  
  Video Embed Field                 Video Embed Media (video_embed_media)                                               Enabled    8.x-2.0-alpha1 

I’m not sure, if this is related to to this patch, or if this problem should be addressed in an other issue, which is related to Media entity audio.

Ralf Eisler’s picture

Found the solution:
composer require 'drupal/media_entity_audio:^2.0'

ruslan piskarov’s picture

The same was for me when I was tried to update from D5.4 to D8.5 TOGETHER with media_entity v8.2.
Updates from media_entity was applied before updating system (drupal core) and as the result the same issue.
However when I tried to update as described there https://www.drupal.org/docs/8/core/modules/media/faq-transition-from-med..., works well without any patch.

Good steps:
Make backup.
Update Drupal core from D5.4 to D8.5 with media_entity v8.1.
Make backup.
Update media_entity v8.1 to media_entity v8.2.

I hope it can help.

hansfn’s picture

Status: Active » Reviewed & tested by the community

The patch in comment 19 fixed the issue for me so I could run update 8201 (when upgrading to Drupal 8.6.1).

keopx’s picture

Status: Reviewed & tested by the community » Needs work

Not works

chr.fritsch’s picture

Is this still a valid issue when you are already on D8.6+?

Older versions of Drupal are not supported, so we could close this issue.

chr.fritsch’s picture

Status: Needs work » Postponed (maintainer needs more info)
karenann’s picture

Recent updates to this module have updated the .install file in such a way that the patch in #19 no longer applies.

Here is the applicable commit https://git.drupalcode.org/project/media_entity/commit/cc4374d06afc820c6...

I can't speak to whether or not the underlying issue in this ticket is still an issue.

bbuchert’s picture

Bumping into the same issue updating Thunder following these instructions: https://thunder.github.io/thunder-documentation/update-2-to-3

Thunder Version
2.49 (Drupal 8.7.7)

bbuchert’s picture

Status: Postponed (maintainer needs more info) » Needs work
bbuchert’s picture

I haven't gotten the time this is the composer.json I'm using.

{
    "name": "burdamagazinorg/thunder-project",
    "description": "Project template for Thunder projects with composer",
    "type": "project",
    "license": "GPL-2.0-or-later",
    "authors": [
        {
            "name": "Daniel Bosen",
            "email": "daniel.bosen@burda.com"
        },
        {
            "name": "Christian Fritsch",
            "email": "christian.fritsch@burda.com"
        },
        {
            "name": "Mladen Todorovic",
            "email": "mladen.todorovic@burda.com"
        },
        {
            "name": "Timo Welde",
            "email": "welde@galaniproject.de"
        },
        {
            "name": "Volker Killesreiter",
            "email": "killesreiter@burda.com"
        }
    ],
    "repositories": [
        {
            "type": "composer",
            "url": "https://packages.drupal.org/8"
        },
        {
            "type": "composer",
            "url": "https://asset-packagist.org"
        }
    ],
    "require": {
        "cweagans/composer-patches": "^1.6",
        "drupal-composer/drupal-scaffold": "^2.2",
        "drupal/console": "^1.2",
        "composer/installers": "^1.2",
        "drush/drush": "~9.7.0",
        "oomphinc/composer-installers-extender": "^1.1",
        "webflo/drupal-finder": "^1.0.0",
        "drupal/fieldblock": "^2.0@alpha",
        "drupal/commerce": "^2.10",
        "drupal/commerce_shipping": "^2.0@beta",
        "drupal/imageapi_optimize_resmushit": "^1.0@beta",
        "drupal/commerce_cart_flyout": "^1.4",
        "drupal/commerce_braintree": "^1.0",
        "drupal/swiftmailer": "^1.0@beta",
        "drupal/redis": "^1.1",
        "wisamx/commerce_simple_stock": "dev-master",
        "drupal/components": "^1.0",
        "drupal/schema_metatag": "^1.3",
        "drupal/commerce_google_analytics": "1.x-dev",
        "drupal/photoswipe": "^2.6",
        "bower-asset/photoswipe": "^4.1",
        "drupal/svg_image": "^1.9",
        "drupal/recreate_block_content": "^2.0",
        "drupal/mailchimp_ecommerce": "^1.3",
        "drupal/commerce_simple_stock": "1.x-dev",
        "behat/mink-selenium2-driver": "dev-master as 1.3.x-dev",
        "thunder/thunder-distribution": "~3.3",
        "drupal/media_entity": "^2.0",
        "drupal/media_entity_image": "^1.3",
        "drupal/video_embed_field": "^2.2",
        "drupal/media_entity_generic": "^1.0"

    },
    "require-dev": {
        "webflo/drupal-core-require-dev": "~8.7.0",
        "webmozart/path-util": "^2.3",
        "drupal/devel": "^2.0",
        "drupal/twig_xdebug": "^1.0"
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "autoload": {
        "psr-4": {
            "DrupalProject\\composer\\": "scripts/composer/"
        }
    },
    "scripts": {
        "drupal-scaffold": "DrupalComposer\\DrupalScaffold\\Plugin::scaffold",
        "pre-install-cmd": [
            "DrupalProject\\composer\\ScriptHandler::checkComposerVersion"
        ],
        "pre-update-cmd": [
            "DrupalProject\\composer\\ScriptHandler::checkComposerVersion"
        ],
        "post-install-cmd": [
            "DrupalProject\\composer\\ScriptHandler::createRequiredFiles"
        ],
        "post-update-cmd": [
            "DrupalProject\\composer\\ScriptHandler::createRequiredFiles"
        ]
    },
    "extra": {
        "installer-types": [
            "bower-asset",
            "npm-asset"
        ],
        "installer-paths": {
            "docroot/core": ["type:drupal-core"],
            "docroot/libraries/{$name}": [
                "type:drupal-library",
                "type:bower-asset",
                "type:npm-asset"
            ],
            "docroot/modules/contrib/{$name}": ["type:drupal-module"],
            "docroot/profiles/contrib/{$name}": ["type:drupal-profile"],
            "docroot/themes/contrib/{$name}": ["type:drupal-theme"],
            "drush/contrib/{$name}": ["type:drupal-drush"]
        },
        "enable-patching": true,
        "patches": {
            "drupal/commerce": {
                "Add Payment Instructions to Reciept": "https://www.drupal.org/files/issues/2019-07-16/2884497-15.patch"
            },
            "drupal/commerce_cart_flyout": {
                "Allow translation of cart flyout item": "https://www.drupal.org/files/issues/2019-01-29/commerce_cart_flyout.patch"
            }
        }
    },
    "config": {
        "bin-dir": "bin/"
    }
}

netgeek123’s picture

This has not been fixed yet.

media_entity   8201                    hook_update_n   Replace Media Entity   
                                                         with Media.
>  [notice] Update started: media_entity_update_8201
>  [error]  Cannot change the definition of field media_revision.revision_uid: field doesn't exist. 
>  [error]  Update failed: media_entity_update_8201 
chr.fritsch’s picture

I am still not able to reproduce this issue. So if someone can provide exact steps to reproduce, I would like to work on it.

netgeek123’s picture

Followed these steps when updating Thunder.
https://thunder.github.io/thunder-documentation/update-2-to-3

drush updb
 [error]  Media Entity Image's functionality has been merged into the core Media module, so it cannot be installed alongside core Media. 

 Requirements check reports errors. Do you wish to continue? (yes/no) [yes]:
 > 

 ---------------------- ----------- --------------- --------------------------- 
  Module                 Update ID   Type            Description                
 ---------------------- ----------- --------------- --------------------------- 
  dropzonejs_eb_widget   8202        hook_update_n   Update configurations for  
                                                     new keys.                  
  media_entity           8201        hook_update_n   Replace Media Entity with  
                                                     Media.                     
  thunder                8301        hook_update_n   Add missing region key to  
                                                     field groups in form       
                                                     display settings.          
  thunder                8302        hook_update_n   Change replace button to   
                                                     remove button on image     
                                                     paragraph form.            
  thunder                8303        hook_update_n   Installs the               
                                                     autosave_form module.      
 ---------------------- ----------- --------------- --------------------------- 

 Do you wish to run the specified pending updates? (yes/no) [yes]:
 > 

>  [notice] Update started: media_entity_update_8201
>  [error]  Cannot change the definition of field media_revision.revision_uid: field doesn't exist. 
>  [error]  Update failed: media_entity_update_8201 
 [error]  Update aborted by: media_entity_update_8201 
 [error]  Finished performing updates.

Media entity 2x is installed;

Media                             Media entity (2.x) (media_entity)                  Enabled    8.x-2.0-beta5    
  Media                             Media entity image (media_entity_image)            Enabled    8.x-1.3          
  Media                             Media Entity Instagram (media_entity_instagram)    Enabled    8.x-2.0          
  Media                             Media entity Pinterest (media_entity_pinterest)    Enabled    8.x-2.2          
  Media                             Media entity slideshow (media_entity_slideshow)    Enabled    8.x-2.0-alpha1   
  Media                             Media Entity Twitter (media_entity_twitter)        Enabled    8.x-2.1          
  Media                             Media Expire (media_expire)                        Enabled    8.x-2.2   

I ran update from update.php;

media_entity module

Update #8201

Failed: Drupal\Core\Database\SchemaObjectDoesNotExistException: Cannot change the definition of field media_revision.revision_uid: field doesn't exist. in Drupal\Core\Database\Driver\mysql\Schema->changeField() (line 650 of 
/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php).

SQLDump of the media_revision table;

-- phpMyAdmin SQL Dump
-- version 4.8.5
-- https://www.phpmyadmin.net/
--
-- Host: localhost:3306
-- Generation Time: Oct 22, 2019 at 12:32 PM
-- Server version: 5.7.28
-- PHP Version: 7.2.7

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `itwerx_gabe`
--

-- --------------------------------------------------------

--
-- Table structure for table `media_revision`
--

CREATE TABLE `media_revision` (
  `mid` int(10) UNSIGNED NOT NULL,
  `vid` int(10) UNSIGNED NOT NULL,
  `langcode` varchar(12) CHARACTER SET ascii NOT NULL,
  `revision_default` tinyint(4) DEFAULT NULL,
  `revision_user` int(10) UNSIGNED DEFAULT NULL COMMENT 'The ID of the target entity.',
  `revision_created` int(11) DEFAULT NULL,
  `revision_log_message` longtext
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='The revision table for media entities.';

--
-- Dumping data for table `media_revision`
--

INSERT INTO `media_revision` (`mid`, `vid`, `langcode`, `revision_default`, `revision_user`, `revision_created`, `revision_log_message`) VALUES
(1, 1, 'en', 1, 1, 1549408261, NULL),
(2, 2, 'en', 1, 1, 1549408512, NULL),
(3, 3, 'en', 1, 1, 1549409225, NULL),
(5, 5, 'en', 1, 1, 1561822127, NULL),
(6, 6, 'en', 1, 1, 1561822729, NULL),
(7, 7, 'en', 1, 1, 1569482872, NULL),
(8, 8, 'en', 1, 1, 1571359289, NULL);

--
-- Indexes for dumped tables
--

--
-- Indexes for table `media_revision`
--
ALTER TABLE `media_revision`
  ADD PRIMARY KEY (`vid`),
  ADD KEY `media__mid` (`mid`),
  ADD KEY `media_field__revision_uid__target_id` (`revision_user`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `media_revision`
--
ALTER TABLE `media_revision`
  MODIFY `vid` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=9;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

There is no revision_uid it is revision_user. That is the problem.

chr.fritsch’s picture

Which versions of Thunder and Drupal are installed before the update?

sershevchyk’s picture

I used Drupal 8.7.6 and Media Entity 8.x-2.0-beta5 and have the same problem when try to run update scripts

In order to run the Media Entity 2.x upgrade, please uninstall and remove from the codebase the contributed "Media" module.
Before continuing, please make sure all modules that provide plugins for Media Entity (or depend on it) have their code updated to their respective 2.x branches. Note that you will probably need to revert to the 1.x branch of the Media Entity module if you want to uninstall existing plugin modules. The following modules depend on media entity and need to be either upgraded or uninstalled: core.
One or more of your existing media types are using the Generic source, which has been moved into a separate "Media Entity Generic" module. You need to download this module to your codebase before continuing.

In logs, when I try to open node with media entity I see next error

Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'revision.revision_user' in 'field list': SELECT revision.vid AS vid, revision.langcode AS langcode, revision.revision_user AS revision_user, revision.revision_created AS revision_created, revision.revision_log_message AS revision_log_message, revision.revision_default AS revision_default, base.mid AS mid, base.bundle AS bundle, base.uuid AS uuid, CASE base.vid WHEN revision.vid THEN 1 ELSE 0 END AS isDefaultRevision FROM {media} base INNER JOIN {media_revision} revision ON revision.vid = base.vid WHERE base.mid IN (:db_condition_placeholder_0, :db_condition_placeholder_1); Array ( [:db_condition_placeholder_0] => 20 [:db_condition_placeholder_1] => 21 ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->getFromStorage() (line 444 of /var/www/html/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

netgeek123’s picture

I was updating to Thunder 3

Media Entity was version 1.2.8 upgrading to 2. The field is named incorrectly. I am not sure when the field name was changed or why.

netgeek123’s picture

I fixed the misnamed field revision_uid... Now it barfs this error.

Update #8201

Failed: Drupal\Core\Database\SchemaObjectDoesNotExistException: Cannot change the definition of field media_revision.revision_timestamp: field doesn't exist. in Drupal\Core\Database\Driver\mysql\Schema->changeField() (line 650 of /docroot/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php).

I am not sure why it is looking for fields that do not exist.

netgeek123’s picture

Ok, I got it to work. I had to manually revert the name of these fields and rerun the update.

  $field_renames = [
    'revision_uid' => 'revision_user',
    'revision_timestamp' => 'revision_created',
    'revision_log' => 'revision_log_message',
  ];

The fields were changed previous to running the update at some point. Anyhow, this fixed the problem. Perhaps some if() statements in the code to work around this problem?

robert_t_taylor’s picture

So, following the suggestion in #45 (Thanks @netgeek123!) I wrapped that $field_renames assignment, as well as the subsequent foreach in a try/catch in /modules/contrib/media_entity/media_entity.install:

  // Note that moved this outside of the try/catch to ensure it ran
  $field_overrides = _media_entity_get_base_field_overrides();

  // wrap in try/catch to avoid "Cannot change the definition of field media_revision.revision_uid: field doesn't exist."
  try {
    $field_renames = [
      'revision_uid' => 'revision_user',
      'revision_timestamp' => 'revision_created',
      'revision_log' => 'revision_log_message',
    ];
    foreach ($field_renames as $old_field => $new_field) {
      $field_columns = $field_definitions[$new_field]->getColumns();
      $field_property_name = $field_definitions[$new_field]->getMainPropertyName();
      $db->changeField('media_revision', $old_field, $new_field, $field_columns[$field_property_name]);
      if (!empty($field_overrides[$old_field])) {
        foreach ($field_overrides[$old_field] as $bundle) {
          $config_factory->getEditable("core.base_field_override.media.$bundle.$old_field")
            ->set('id', "media.$bundle.$new_field")
            ->set('field_name', $new_field)
            ->save(TRUE);
          $config_factory->rename("core.base_field_override.media.$bundle.$old_field", "core.base_field_override.media.$bundle.$new_field");
        }
      }
    }
  } catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
  }

This allowed me to get past the error, and I can repeat this as needed against production database dumps without the need to revert the field names.

rumenx’s picture

StatusFileSize
new2.37 KB

I created a patch based on the solution in the previous comment. It worked for me.

karimbou’s picture

Tried the upgrade media_entity path coming from 8.4 to 8.5 (media_entity 2.x needed drupal core 8.6) so I upgraded to 8.6, downloaded media_entity_generic, updated all modules (media_entity_image) removed a custom image module, then ran 8.6 drush updb and i get this :

Do you wish to run all pending updates? (y/n): y
Field storage definition for 'revision_user' could not be found.                                                                                                                                                             [error]
Performing media_entity_update_8200  

I'm starting to not know what to do should i retry this in 8.4.8 with media_entity 2.x ? Why this documentation https://www.drupal.org/docs/8/core/modules/media/faq-transition-from-med... talks about Drupal 8.5x when you actually need 8.6.x ? When you then go to 8.6.x should you revert the codebase of media_entity 2.x and actually run drush updb for core first maybe ?

anybody’s picture

We've been using the patch in #47 several times now to be able to switch to Media in Core through media_entity 2.0.

anybody’s picture

Status: Needs work » Needs review

Setting needs review as of #47 and #49

benstallings’s picture

Status: Needs review » Closed (outdated)

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.