Tuesday, February 28, 2012

Drupal 6 to 7 - clear errors by dropping Upload DB table

another guy figured this out -- I am just afraid to lose the solution -- so I copying it here --

I kept getting the error below when trying to run the update.php
grrrr!

Update #7061

Failed: PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry

the following worked -- from
http://user25.com/drupal/upgrade6-7-DB-schema-update-error-failed-7061-solution

Drupal 6 to 7 Upload/File module Database Schema update error - Solution

The following updates returned messages
system module
Update #7061
Failed: DatabaseSchemaObjectExistsException: Table system_update_7061 already exists. in DatabaseSchema->createTable() (line 629 of /---/includes/database/schema.inc).
Changes in Drupal 7
I notice that the Drupal core upload module has been removed from the latest version of Drupal (7). There is therefor a script in the system.install (also run during Database Schema updates /update.php) that is intended to take the data in the 'upload' database table and load it into the database table for the new file CCK field (that is the new way of handling file uploads in Drupal - in addition to using third-party solutions such as IMCE and the CKEditor WYSWYG commercial version of the editor).

DB Schema Update error
During the final stages of upgrading from Drupal 6 to Drupal 7 on this website - idonny.com there were 11 updates that could not clear from the update log resulting in the error message at the beginning of this entry. As usual, I checked on the Internet and Drupal-org in particular for what others have experienced and reported on this issue. One document (http://drupal.org/node/966210) came close to describing and identifying the problem. The document on Drupal.org refers to the existence of non-unique database entries (or just different by case) and the possibility that the row in question (file names/path) is of a type that is case-aware/sensitive. Being that I do not have too many uploads (apart from portfolio images that I am anyway rebuilding as part of a refresh of the portfolio section, and login public keys), I resolved to trunctate the database table "upload" so as to eliminate all upload entries and thus by-pass/solve the problem of the rows with identical values. That did however not solve the problem (To be safe, I created a new tables with the same schema and copied the data to it to avoid progressively damaging the database structure).


Solution
The approach that worked for me was to DROP the upload table.
I looked in the includes/database/schema.inc file on the line mentioned #629 and found that there was just an abstract function definition for throwing the error that we see on the screen.
* @throws DatabaseSchemaObjectExistsException
* If the specified table already exists.
*/
public function createTable($name, $table) {
if ($this->tableExists($name)) {
throw new DatabaseSchemaObjectExistsException(t('Table %name already exists.', array('%name' => $name)));
}
$statements = $this->createTableSql($name, $table);
foreach ($statements as $statement) {
$this->connection->query($statement);
}
}
So I decided to find if there are other DB tables and code instances that are explicitly referring to the required schema that is either unmodifiable of conflicting. I see that the file at /---/modules/system/system.install has a code sequence that is referencing the DB schema update #7061 and is also consistent with the fact that if the DB table exists, thent he error should be thrown
/**
* Migrate upload.module data to the newly created file field.
*/
function system_update_7061(&$sandbox) {
if (!db_table_exists('upload')) {
return;
}
So I dropped the DB table [DROP upload;] in mysql and was able to successfully update the core DB schema