Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Upon attempting to perform some database upgrades on a site, I have discovered that should the 'file_metadata' table already exist within your database schema, the rest of the updates will gracefully fail.
To fix this file_entity.install#L961 just needs to be wrapped within a db_table_exists
check. Will supply a patch for this fix shortly.
Comment | File | Size | Author |
---|---|---|---|
#9 | file_entity-2183267-update-error-9.patch | 962 bytes | dooug |
#1 | file_entity-wrap-db-creation-in-exists-check-2183267-1.patch | 374 bytes | jacobbednarz |
Comments
Comment #1
jacobbednarz CreditAttribution: jacobbednarz commentedComment #2
jacobbednarz CreditAttribution: jacobbednarz commentedComment #3
Dave ReidI'm curious how this table existed before an install? Was it installed at one point but never uninstalled?
Comment #4
jacobbednarz CreditAttribution: jacobbednarz commentedThat is definitely a possibility - we didn't get the full backstory however we just wanted to ensure that if this popped up again, the update wouldn't fail and just pass over it.
Comment #5
jacobbednarz CreditAttribution: jacobbednarz commentedHey,
Just realised this is still pending me (apologies!). As mentioned above it was more that we wanted to be sure if this ever popped up again, this module would handle it nicely and perform the additional check.
Thanks.
Comment #6
dooug CreditAttribution: dooug at Promet Source commentedI have also run into this issue updating from 7.x-2.0-unstable7 to 7.x-2.0-beta1+25-dev.
When running
drush updb -y
, I have lots of updates, but it dies atfile_entity_update_7211
:Oddly though, I tried this on a fresh install and couldn't reproduce. But I can confirm that before I updated, the
file_metadata
table was in the database, but the schema_version is at 7204. I've inherited the site, so I can speak for why this is the case. My suspicion is this scenario:1. someone updated the code
2. ran the database updates
3. imported a db dump. which reset the schema_version, but didn't drop the newly added tables
This was documented previously in a similar ticket: #1901886: Update-Problems
Despite this probably being a user error, the patch does avoid the error preventing the updates. And it is a pretty harmless code change. RTBC++
Comment #7
dooug CreditAttribution: dooug at Promet Source commentedAlso, I found the location module had a simliar problem with a similar solution that committed: http://cgit.drupalcode.org/location/commit/?id=e61c0d5
Comment #8
steinmb CreditAttribution: steinmb commentedHmm Should we really write code like this? I have only seen stuff like this in scenarios like suggested in #6, or where admins mixed up media 7.x-1 and 7.x-2.x, jumped forth and back without rolling back from backup. I mean the error is a indication that stuff is wrong and they might have more in their installation broken. I think silently ignoring it might not be safe.
Comment #9
dooug CreditAttribution: dooug at Promet Source commented@steinmb, that is a really good point.
The site owners should responsible for their broken installs, not the module. Makes sense, the module can't account for all scenarios breaking the installation of the module.
If anything, is there a better way to exit the update script that doesn't prevent other update scripts from running, such as throwing the DrupalUpdateException?
The result is the same, an error message and the updates are halted. However, this probably follows better practice. Patch attached.
Is there a way to bypass an erroneous update in order to avoid preventing any other modules' updates?
Comment #10
jacobbednarz CreditAttribution: jacobbednarz commentedI would support writing defensive code like this in order to prevent allow safe upgrade paths - despite how people are managing their sites. Sure, they shouldn't be manually touching schema versions but if they do the module should be smart enough to say, "Hey! I already have that table, I'm just going to continue on with my business".
Comment #11
lcontreras CreditAttribution: lcontreras commentedI update drupal core to 7.43 version on my local enviroment.
Everything was good, but when I upload the code generated to update other server (I have a local copy from it), I got the same error: There are updates for the modules, I run the update.php and got the same error: file_metadata already exists (file_entity module).
Recently I just noticed that in production enviroment file_entity module looks with the version 7.x-2.0-beta2 and media module, looks with 7.x.1.5 version. On my local enviroment the situation is different, file_entity and media modules have the 7.x.1.5 versions, even when the code for file_entity is older (7.x-2.0-beta2).
I don't want to delete file_metadata table on production.
Thanks.
Comment #12
joseph.olstadThis appears to still be an issue.
Comment #13
joseph.olstadI believe that previous versions of the file_metadata table are probably fine and don't need to be changed.
on mine in mysql, it has 3 columns as follows:
I might suggest changing patch 9, instead of throwing an exception, maybe just drupal_set_message with a warning
Comment #14
joseph.olstadTried to reproduce this by installing an older pre 1.x file_entity (before it was a project it was a sub module of media 1.x) but could not reproduce the issue, when I upgraded from Media 1.6 to 2.0 I downloaded file_entity 2.0-beta3 and ran the updates and they all worked no issues.
Comment #15
joseph.olstadComment #16
angel2000 CreditAttribution: angel2000 commentedI have same issue, What can i do?
Comment #17
Francis47 CreditAttribution: Francis47 commentedTried everything, and eventually the only thing that worked was to drop the table in question.