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.
Running update from 7.x-1.12 to 7.x-1.13 generates this error:
ctools module
Update #7002
Failed: PDOException : SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes: ALTER TABLE {ctools_object_cache} CHANGE `name` `name` VARCHAR(255) NOT NULL; Array ( ) in db_change_field() (lige 3076 in /Sites/example.com/includes/database/database.inc).
Running Drupal 7.56 on PHP 7.1.12 and MySQL 5.6.38.
Comment | File | Size | Author |
---|---|---|---|
#50 | 2941920-50.patch | 4.49 KB | joelpittet |
Comments
Comment #2
xmacinfoComment #3
xmacinfoComment #4
joseph.olstadEssaye un drush cc all avant de faire drush updb
Bizarre un peu parce qu'on change le champ de 128 à 255 varchar
? Ça fait pas de sens
Peut être une faille dans MySql 5.6.38
Comment #5
l8518 CreditAttribution: l8518 commentedI ran into the same problem running. If I remove name from the PK I can change the column.
Might be that the problem is related to:
https://stackoverflow.com/questions/8746207/1071-specified-key-was-too-l...
Comment #6
Egmund CreditAttribution: Egmund commentedSame problem:
The following updates returned messages
ctools module
Update #7002
Failed: PDOException: SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes: ALTER TABLE {ctools_object_cache} CHANGE `name` `name` VARCHAR(255) NOT NULL; Array ( ) i db_change_field() (linje 3076 af /home2/ordblind/public_html/includes/database/database.inc).
Comment #7
scareyclott CreditAttribution: scareyclott commentedSame here
Update:
ctools module
Update #7002
Failed: PDOException: SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes: ALTER TABLE {ctools_object_cache} CHANGE `name` `name` VARCHAR(255) NOT NULL; Array ( ) in db_change_field() (line 3076 of /home/ra261/richadventure.com/includes/database/database.inc).
Comment #8
joseph.olstadTry cache clear then updb again? Does that help?
It's just a cache table.
Maybe truncate table ctools_object_cache
The updb, however cache clear should do it.
Comment #9
Robert Gomez CreditAttribution: Robert Gomez commentedFrom reading this issue I suspect that the error is caused because my database engine is set to MyISAM. Years ago I changed all my tables to be MyISAM to fix a compatibility issue with my host, MediaTemple.
Via phpMyAdmin I ran the following SQL command:
ALTER TABLE `ctools_object_cache` ENGINE = InnoDB;
Then ran the cTools update and no longer got the error. Tested on two of my sites and seemed to work in both.
NOTE: I am a noob who normally interacts with Drupal via the Web UI, so please let me know if this is an incorrect approach. I know little to nothing about MySQL and backend-ish stuff.
Comment #10
joseph.olstadmakes sense, yes you should normally be using InnoDB these days for most (or all) Drupal tables when using MySQL except if your database administrator says otherwise (without getting into the details of why you might want to run MyISAM in some cases).
Comment #11
joseph.olstadRTBC #9 , for those having this issue when using MySQL (or MariaDB or Persona), you'll want to make sure this table is using the InnoDB engine and not the MyISAM. Switch it as described in #2941920-9: Update 7002 Specified key was too long
Comment #12
joseph.olstadTo improve this, we could write a patch and modify the ctools.install file ctools_requirements checking that if a mysql driver is in use to perform a check to ensure that the InnoDB engine is enabled for the ctools_object_cache table making sure that MyISAM is not enabled for this table.
Comment #13
joseph.olstadWith all that said, I wonder if there's a way to make this work for those that are stuck on MyISAM due to hosting limitations (some service providers only allow MyISAM and not InnoDB).
Comment #14
joseph.olstadComment #15
seenafallah CreditAttribution: seenafallah commentedMy table storage engine is InnoDB and I've cleared my drupal caches but still gets this problem!
Any other solution?!
Comment #16
joelpittetThere is no patch so setting the status back to Active and against the 1.x-dev branch.
Comment #17
GilAnder CreditAttribution: GilAnder commented#9 worked for me. Thx
Comment #18
guruken1 CreditAttribution: guruken1 commented#9 worked for me.
Comment #19
joelpittetThe solution in #9 is definitely the way to go.
This issue has shown up in a bunch of other modules. Seems to be because it's a key and large keys. So please change the table to
InnoDB
.Comment #20
xmacinfoSolution in #9 works perfectly.
I've read that since UTF8 is multibytes, it requires more storage for indexation. Maybe that MyISAM and UTF8 require more than 255 lenght.
Comment #21
Alex Oliver Perez CreditAttribution: Alex Oliver Perez commented#9 worked for me as well. Thank you!
Comment #22
SuperTyp CreditAttribution: SuperTyp commented#9 worked, thank you very much.
Comment #23
pietrocap CreditAttribution: pietrocap commented#9 worked for me too. Thanx!
Comment #24
scareyclott CreditAttribution: scareyclott commented#9 is the answer, Thank you
Comment #25
seenafallah CreditAttribution: seenafallah commentedDidn't worked for me!
My table was already InnoDB but still have this problem!
Any other solutions?
Comment #26
joseph.olstad@seenafallah , please refer to this instruction, it will most likely solve your issue. #2941951: MyISAM tables throw PDOException on updating ctools module 7.x-1.13
Comment #27
seenafallah CreditAttribution: seenafallah commented@josepholstad Both my system and ctools.cache Storage Engine are InnoDB but I can't do the update!
Comment #28
joelpittet@seenafallah are you getting the same error message then?
We'll need more information to help you.
Please let us know what version of MySQL you are running?
Is it UTF8 or UTF8MB4 encoding or something else?
Is
innodb_large_prefix
enabled?SHOW GLOBAL VARIABLES LIKE 'innodb_large%';
Comment #29
seenafallah CreditAttribution: seenafallah commented@joelpittet The version of MySQL is 5.1.73. the tables charset is utf8mb4 and innodb_large_perfix is off!
Comment #30
joelpittetHow did you get utf8mb4 on MySQL 5.1? I thought that didn’t get added till 5.5.
https://dev.mysql.com/doc/relnotes/mysql/5.5/en/news-5-5-3.html
Would be worth trying to get large prefixes enabled but I don’t feel qualified to give you how to do that.
I’d really hope not to revert this because it has a possibility to truncate data.
Comment #31
joseph.olstad@seenafellah the other solution is not the same as #9, the reported solution in the other issue has a couple queries to find all myisam tables not just one and update to innodb.
#2941951: MyISAM tables throw PDOException on updating ctools module 7.x-1.13
Comment #32
tschewe CreditAttribution: tschewe as a volunteer commentedI'm one of those who must use MyISAM due to hosting limitations.
Of course, I'd far sooner see you change CTools to be able to use either MyISAM or InnoDB as you've left me (and no doubt many others) with the option of either not doing the update or moving sites to another provider.
Not knowing much about things like this, why is it suddenly necessary to cause significant upset to people by creating this limitation?
Comment #33
joelpittet@tschewe which host doesn't allow Innodb out of curiosity.
Here's the original bug that we fixed that caused this issue btw.
#2575673: ctools_object_cache.name is not big enough
Comment #34
seenafallah CreditAttribution: seenafallah commented@josepholstad All my tables are InnoDB!
Comment #35
seenafallah CreditAttribution: seenafallah commented@joelpittet So should I try the solution in that link or its the risk?!
If I turn on large_prefix wouldn't be okay?!
Comment #36
cozzamara CreditAttribution: cozzamara commentedI had same issue updating to 7.x.1.13 from 7.x.1.12 after updating database. I'm using Mysql.
Comment #37
Robert Gomez CreditAttribution: Robert Gomez commented@joelpittet I'm on MediaTemple's managed host, Gridserver. To be clear, they allow Innodb, but Drupal takes a huge performance hit and throws PDO Exceptions all over the place when certain tables aren't MyISAM. I don't know why this is the case. For some background, this thread is where I found out I needed to convert my database engine to MyISAM: https://www.drupal.org/node/1041298#comment-5188198
This was years ago, so MediaTemple might have fixed some of these problems? This ctools update was the first time in all these years that I encountered a conflict because of MyISAM tables.
Comment #38
xmacinfoTo help us debug this issue, please provide the following information:
ctools_object_cache
table (e.g. MyISAM)ctools_object_cache
table (e.g. UTF8).mysql-utf8-and-indexing, February 21, 2015
MySQL, UTF8 and Indexing
Comment #39
cozzamara CreditAttribution: cozzamara commentedMySql version: 5.7.21-0ubuntu0.16.04.1
utf8_general_ci
MyISAM
latin1_swedish_ci
Comment #40
ajoscham CreditAttribution: ajoscham commentedHi, Changing DBEngine was not possible in my case and what i did was to change the code in install File as following:
function ctools_update_7002() {
db_change_field('ctools_object_cache', 'name', 'name', array(
'type' => 'varchar',
'length' => '100',
'not null' => TRUE,
));
}
and it solved my problem.
cheers!
Comment #41
duckzland CreditAttribution: duckzland commentedAny reasons why it shouldnt just use Text instead of varchar?
Comment #42
nairb CreditAttribution: nairb commented#9 seems to fix the issue.
Comment #43
joelpittet@duckzland the only reason this is an issue is because it’s used in an index.
We could remove the index but that could have some performance issues.
Comment #44
joelpittet@seenafallah with enough backups it’s fine to change, it’s also the default for newer versions of MySQL. I just don’t want to claim expertise (IANADBA)
Comment #45
tschewe CreditAttribution: tschewe as a volunteer commented@joelpittet I have Drupal 7 sites hosted with Shaw Business which turns out to be a reseller for megawebservers.com. They do not provide InnoDB and have no plans to add it in the near future.
Unfortunately, I seem to find out about host limitations after something goes wrong like this. No way of knowing the requirement up front as it changed in mid-stream and it's a nuisance to move.
I guess it all comes down to balance. I can't use my sites fully now without a move, and others have to limit file name size if it doesn't change. Which choice causes the least damage?
Comment #46
joelpittet@tscheweDo you know what version of MySQL they are running out of curiosity?
Comment #47
joelpittetI think I have a "make everybody happy" solution, so here's a patch for people to test.
$name
argument so that it doesn't break when it's too long.Comment #48
japerryThis is a great start! Two things I'd probably want get answers on:
1) If I already updated, we need a way to revert back the change. So we'd need another update hook to change the schema key back.
2) The cache should probably be cleared on the update, otherwise you have to wait for cron to execute to get the old cache entries cleared.
Comment #49
xmacinfoComment #50
joelpittet1) I was thinking it wasn't a big deal to leave it, but here's an update hook to move it back.
2) The cost of leaving the cache there is likely super minimal for a week but I through in a
db_delete()
for good measure.Comment #51
BartNijs CreditAttribution: BartNijs commentedPatch #50 works for me.
Comment #52
aramboyajyan CreditAttribution: aramboyajyan commentedPatch #50 worked for me as well.
Comment #53
DamienMcKennaIf it's going to run md5() on every value going into the 'name' column, why not just change it to varchar(32)?
OTOH the 'cid' key field in the core cache tables is 255, so maybe this can be solved another way?
Comment #54
DamienMcKennaAh, I checked the schema again and saw it uses a compound primary key with three fields. Ick.
Are the extra parts of the key really needed or could it change to just 'sid'?
Comment #55
DamienMcKennaAh, 'sid' is the session ID, so no, that can't be a solitary primary key.
Comment #56
DamienMcKennaWould it blow people's minds if we added a new primary key to replace the three separate ones?
Comment #57
DamienMcKennaFood for thought. I haven't tested it yet ;-)
Comment #59
DamienMcKennaOh for crying out loud, Damien.
Comment #61
DamienMcKennaTestbot finally worked. Awesome.
Comment #62
tschewe CreditAttribution: tschewe as a volunteer commentedServer version: 5.5.58-MariaDB
Thank you very much for reconsidering. I'm sure that you have saved many headaches for Chaos Tools users.
To save me mucking about in an area I'm not that familiar with, instead of applying the patch, can I just wait and apply the next update and accomplish the same thing?
Comment #63
DamienMcKenna@tschewe: Yes, I'm hoping we'll have some agreement in a day or two and then a new release can be made.
Comment #64
vagelis-prokopiou CreditAttribution: vagelis-prokopiou as a volunteer commentedThe "ctools-n2941920-59.patch" did not work for me.
It created db errors that I noticed when i tried to login to the site, and the site broke with "The site encountered an error".
Server: 10.1.26-MariaDB-0+deb9u1
Comment #65
k.elizabeth CreditAttribution: k.elizabeth commentedI applied the
ctools-n2941920-59.patch
, however I am still getting the sameSQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes
when I rundrush updb
.Comment #66
joelpittetI think because the patch doesn't remove
ctools_update_7002
. Probably needs to be removed like I did in #50Comment #67
k.elizabeth CreditAttribution: k.elizabeth commentedPERFECT; Thanks joelpittet, #50 took care of that!
Comment #68
joelpittetHere's the patch from #59 with the changes needed from #50 to avoid the error for those who get it.
Comment #70
DamienMcKennaI don't see the benefit of reverting the 'name' field back if it's no longer part of the primary index, it's just going to cause the problem that lead to it being increased in the first place.
Oh, and in #59 I forgot to delete the two unnecessary fields.
Comment #71
DamienMcKenna(and I still need to actually manually test the patch... duh Damien)
Comment #73
joelpittet@DamienMcKenna the failure most people seem to be having is the
ctools_update_7002
update like I mentioned. So without removing that change in the previous update it won't get past that.Comment #74
DamienMcKennaOh now I get it. Duh Damien.
Yep, I concur Doctor.
Comment #75
joseph.olstadya it gets a bit tricky when it comes to fixing .install files. sorry I haven't had a chance to review any of these patches but some great work being done here, I like Damiens approach as well having peeked at it and followed the thread a bit. I have nothing against MyISAM , it is a very fast engine and I can understand why some people would want to use it. For speed, my servers are using brute force for speed, I've got high performance SSD on a raid array and I use InnoDB, that is why I didn't have this issue others are not so lucky , I spent a fortune on my servers.
Comment #76
DamienMcKennaThe schema functions don't need to change, just update 7002.
Comment #77
xmacinfo@joseph.olstad: It's not exactly that some users prefers MyISAM. MyISAM tables are there principally because old Drupal 6 sites where using MyISAM before upgrading to Drupal 7. The upgrades did not force InnoDB.
Sometimes we notice that a database table is still on MyISAM only after we face an issue.
Finally, the index issue also affects some users who are already on InnoDB, like in #29 and #34.
Comment #78
Stephen OllmanAfter applying patch #76 am now getting total site outage with error:
PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'c.obj' in 'where clause': SELECT s.uid, c.updated FROM {ctools_object_cache} c INNER JOIN {sessions} s ON c.sid = s.sid WHERE s.sid <> :session_id AND c.obj = :obj AND c.name = :name ORDER BY c.updated ASC; Array ( [:session_id] => TySAGxTgW82KHlLvMyNGqSIP34kj0U-0VJnUZ6zwx9U [:obj] => view [:name] => panoptic_server_get_sites ) in ctools_object_cache_test() (line 146 of /home/panoptic/public_html/sites/all/modules/ctools/includes/object-cache.inc).
Comment #79
Stephen OllmanShould patch #76 work by itself, or is there another patch I need to apply?
Comment #80
DamienMcKenna@Stephen Ollman: Thanks for the review. Patch #76 should work on its own. The error you saw indicates that the patch needs work.
Comment #81
DamienMcKennaI wonder if we should just go back to #50? *sigh* The 'name' column could then be made smaller as it'd only need to deal with 32 characters.
Comment #82
Stephen OllmanWARNING!!! patch #76
After applying patch #76 I was unable to access my site and had to literally roll back the code and database in order to get it to work again, as the patch updates the database removing exiting columns and as such rolling back the code fails just as bad.
Comment #83
joelpittetI guess this probably needs to be said(maybe a few times):
*Don't test this out in production.*
It's dealing with the database schema, though it's only a cache table... so make sure you take a dump of it and it's create schema and just re-import it after you revert the patch.
The idea @DamienMcKenna has is much cleaner than my
md5
solution so I was pulling for that one even though more things to check. In this case thesid
that is getting dropped is also used as asessions
foreign key inctools_object_cache_test()
andctools_object_cache_test_objects()
which would have to be changed but I think the join may become much less efficient, thought @DamienMcKenna?And I very much appreciate his effort and all of yours for testing this to help out the rest of the community who need and/or wants to keep their engine.
Comment #84
joseph.olstadwondering if a hook_requirements would be appropriate in this case.
So add a hook_requirements phase that checks to see if mysql driver is in use, if it is, check the table engine for ctools_object_cache_test_objects() , if it is myisam, provide helpful information such as instructions on changing the table engine to innodb.
the same code could be called from the ctools_update_7200 , prevent the upgrade if myisam is in use.
this way, we avoid the complication of supporting myisam, while at the same time providing a helpful instruction on changing the engine to innodb?
or go the patch 50 way. Not sure, maybe just looking for lazy solution.
FYI: this issue was discussed by the core maintainers back in 2010:
#821768: hook_requirements() should warn if no transaction support, provide INNODB upgrade script
but they never actually did anything about it.
Comment #85
mkolar CreditAttribution: mkolar as a volunteer commentedHello I had the same issue, #50 helped.
Comment #86
goose2000 CreditAttribution: goose2000 commentedOkay, #9 worked for me - was doing update from Version: 7.x-1.12 --> Version: 7.x-1.13. Thank you! Don't call Chaos Tools for nothing... ;)
Comment #87
chris.jichen CreditAttribution: chris.jichen commented#50 works for me!
Comment #88
keypetery CreditAttribution: keypetery as a volunteer commented#9 seemed to work for me
Comment #89
MustangGB CreditAttribution: MustangGB commentedI like the look of #76 a lot more than #50, just needs a bit of ironing to get it over the line.
Comment #90
joseph.olstadfor Damiens patch #2941920-76: Update 7002 Specified key was too long
perhaps to deal with #2941920-78: Update 7002 Specified key was too long add a simple cache clear on the first line of:
Comment #91
DamienMcKenna@joseph.olstad: What would the benefit be of clearing all caches?
Comment #92
japerryLooking at the two approaches, I think #50 should work for both those who've successfully updated and those who have seen the failures in this issue. Lets put #50 in.
Comment #93
joelpittetIn order to unblock this and another issue around tests not working for PHP 5.3. I'm going to commit #50 and if people are interested they can tackle alternative and maybe better solutions in a follow-up.
Comment #95
joelpittetThanks for everybody on the patch for contributing! I've pushed this to -dev and plan to release this afternoon.
Comment #96
DamienMcKennaWoohoo! Thanks everyone!
Comment #97
joseph.olstadStanding on the shoulders of giants, thanks everyone!
Comment #98
xmacinfoThank you all! That was an interesting problem.
Comment #99
tschewe CreditAttribution: tschewe as a volunteer commentedI just performed the 7.14 update without problem.
Thank you very much for making the change to continue to support MyISAM tables! I am sure that many will join me in expressing that sentiment as it has saved us no end of trouble.
Comment #101
sam452 CreditAttribution: sam452 as a volunteer commentedOk, coming into this a year later, I updated ctools module to 7.x-1.15. I had no trouble update the db on local, and a staging site, but the production site update.php fails with this message:
An AJAX HTTP request terminated abnormally. Debugging information follows. Path: https://mysite.org/update.php?op=selection&token=hashtoken&op=do StatusText: ResponseText: ReadyState: 4
Watchdog reports no error. I had figured any issues related to this would be resolved. The staging db is an older clone of the production site.
Found this issue, but this table is running InnoDb. Parsing through the responses it appears that it is resolved, but it stops all other updates.
Looking at the ctools.install I see this:
This may not be a real issue per se with ctools or perhaps more with the update.php file not understanding how to deal with empty updates?
At least it seems that ctools_update_7003() resets the name back to 128 characters and my site shouldn't crash? Just that subsequent db_updates on production are not run yet.
Comment #102
xmacinfoYou should open a new issue and add a reference to this one.
Do you have access to Drush in production? I would issue a "drush updb" command which bypass Ajax.