Databases: DDL Error - upgrading moodle 1.9.4 to 2.0.3 ( Duplicate entry '8138-email_send_count' count for key 'mdl_userpref_usenam_uix')

Databases: DDL Error - upgrading moodle 1.9.4 to 2.0.3 ( Duplicate entry '8138-email_send_count' count for key 'mdl_userpref_usenam_uix')

by Danny Moakamedi -
Number of replies: 3

hi,

I tried to upgrade our moodle site from 1.9.9 version to the latest 2.0.2 avalaible and I got this message  database mysql) :

Am using(LAMP): php 5.3.6 , mysql 5.1.57 - can this have have any effect on the upgrade? i didnt have any problem upgrading 1.8.4 to 1.9.12.

 

Average of ratings: -
In reply to Danny Moakamedi

Re: Databases: DDL Error - upgrading moodle 1.9.4 to 2.0.3 ( Duplicate entry '8138-email_send_count' count for key 'mdl_userpref_usenam_uix')

by Mignonne Davis -

Did you ever find a fix to this?  I've been trying to upgrade as well.  Tried from 1.9.7 to 2.0 and then 1.9.7 to 2.1 ...my error is slightly different, but close to yours:

DL sql execution error

More information about this error

Debug info: Duplicate entry '6350-auth_forcepasswordchange' for key 'mdl_userpref_usenam_uix'
CREATE UNIQUE INDEX mdl_userpref_usenam_uix ON mdl_user_preferences (userid, name)
Stack trace:
  • line 400 of /lib/dml/moodle_database.php: ddl_change_structure_exception thrown
  • line 655 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
  • line 88 of /lib/ddl/database_manager.php: call to mysqli_native_moodle_database->change_database_structure()
  • line 75 of /lib/ddl/database_manager.php: call to database_manager->execute_sql()
  • line 892 of /lib/ddl/database_manager.php: call to database_manager->execute_sql_arr()
  • line 5431 of /lib/db/upgrade.php: call to database_manager->add_index()
  • line 1417 of /lib/upgradelib.php: call to xmldb_main_upgrade()
  • line 277 of /admin/index.php: call to upgrade_core()
In reply to Mignonne Davis

Re: Databases: DDL Error - upgrading moodle 1.9.4 to 2.0.3 ( Duplicate entry '8138-email_send_count' count for key 'mdl_userpref_usenam_uix')

by Mignonne Davis -

I fixed it!  You need to look at the table mdl_user_preferences for userid = 6350 and name=auth_forcepasswordchange (or email_send_count, etc.).  You'll end up seeing more than one entry and you need to delete all but one of the records because this is supposed to be unique, ie.:

i.e.: 

 

the debug info  was:  duplicate entry '6532-email_send_count' for key mdl_userpref_usename_uix'  

So, the commands I ran were:

select * from mdl_user_preferences where name="email_send_count" and userid = 6532; +-------+--------+------------------+-------+
| id    | userid | name             | value |
+-------+--------+------------------+-------+
| 10347 |   6532 | email_send_count | 79    |
| 11196 |   6532 | email_send_count | 41    |
+-------+--------+------------------+-------+
2 rows in set (0.00 sec)

mysql> delete from mdl_user_preferences where name="email_send_count" and userid=6532 and id=10347;
Query OK, 1 row affected (0.00 sec)


In reply to Mignonne Davis

Re: Databases: DDL Error - upgrading moodle 1.9.4 to 2.0.3 ( Duplicate entry '8138-email_send_count' count for key 'mdl_userpref_usenam_uix')

by Pavel Krejci -

Same problem here, this should fix the whole table in 1 command:

DELETE FROM `mdl_user_preferences` WHERE `id` IN (SELECT id FROM (  SELECT id,userid,name,count( * ) AS duplicities FROM `mdl_user_preferences` AS A GROUP BY userid,name HAVING COUNT( * ) >1 )  B );

You can use "SELECT *" instead of "DELETE" to preview the affected entries.

Average of ratings: Useful (1)