In general Drush can't corrupt your database, as it's a software which just sends the SQL queries.
However this error can be related to newer version of MySQL, as of 5.5.7, InnoDB always uses the fast truncation technique (which is equivalent to DROP TABLE
and CREATE TABLE
). So it no longer performs a row-by-row delete for tables with parent-child foreign key relationships, therefore TRUNCATE TABLE
returns an error for such tables.
See: 2.11.1.1 Changes Affecting Upgrades to 5.5
This already has been reported in #2229013 for Drupal core.
So you should either:
consider using different data structures:
non-InnoDB,
use redis/memcached for your cache management (so this won't happen),
try clearing your caches in different way, e.g.
echo "SHOW TABLES LIKE 'cache%'" | drush sqlc --extra=--skip-column-names | xargs -L1 -I% echo "DELETE FROM %;" | drush sqlc --extra=-v
upgrade your Drupal to 8 and see if the same happens (
drush cr
),use different database (maybe will work in MariaDB?),
downgrade your MySQL to <5.5.7,
patch the Drupal core by replacing
TRUNCATE
withDELETE
statement,You may also consider the condition like
if ($mysqlversion > 5.57 AND $cache_table_type = 'innodb') { // DELETE } else { // TRUNCATE }
.or wait until the fix is provided for Drupal core (#2229013).