Did you remember to make the first column something unique in your call to get_records? Duplicate value '2' found in column 'id'.

Did you remember to make the first column something unique in your call to get_records? Duplicate value '2' found in column 'id'.

by Kate Rhodes -
Number of replies: 3

Not sure what happened when... BUT when try to view issued certificates, we get this error message displayed for all the issued certificates:

Did you remember to make the first column something unique in your call to get_records? Duplicate value '2' found in column 'id'.

  • line 1005 of /lib/dml/mysqli_native_moodle_database.php: call to debugging()
  • line 744 of /mod/certificate/lib.php: call to mysqli_native_moodle_database->get_records_sql()
  • line 104 of /mod/certificate/view.php: call to certificate_get_issues()

 

There are pages of this message I assume for each issued certificate, so the duplicate value changes for each message.

UPDATE: It's only doing this in 5 out of 9 courses.The other 4 courses we are able to view the certificates no problem.

 

With debugging turned on I get this:

Error: mdb->get_record() found more than one record!

  • line 1427 of /lib/dml/moodle_database.php: call to debugging()
  • line 1387 of /lib/dml/moodle_database.php: call to moodle_database->get_record_sql()
  • line 1366 of /lib/dml/moodle_database.php: call to moodle_database->get_record_select()
  • line 644 of /mod/certificate/lib.php: call to moodle_database->get_record()
  • line 88 of /mod/certificate/view.php: call to certificate_get_issue()

 

How do I fix this???? I've never seen this before and I'm not sure where in the database I need to go to look for this duplicate value.

Average of ratings: -
In reply to Kate Rhodes

Re: Did you remember to make the first column something unique in your call to get_records? Duplicate value '2' found in column 'id'.

by Jean-Michel Védrine -

Hello Kate,

You seem to have a problem in your database : several certificate issues for the same user and the same certificate instance.

The code works on the assumption that there is only one certificate issue for a given user and a given certificate instance.

Other than manual edition of the database, I don't know of any solution to this problem.

The problem is in the certificate_issues table, look for records that have the same values for both userid AND certificateid fields

I hope you don't have too many of such duplicate rows ! It would of course be possible to write a script to correct the problem but I don't know if anybody has written such a script.

To know which row to delete look at the timecreated column, it's an unix timestamp so the greater value is for the most recent record, IMHO this is the one you should keep.

Of course backup your database before attempting to suppress any data !

I don't know how this duplicate rows were created in your database.

In reply to Jean-Michel Védrine

Re: Did you remember to make the first column something unique in your call to get_records? Duplicate value '2' found in column 'id'.

by Kate Rhodes -

Thank you! I will go look at the database and see if I can get it straightened out. Your help is very much appreciated.

 

In reply to Kate Rhodes

Re: Did you remember to make the first column something unique in your call to get_records? Duplicate value '2' found in column 'id'.

by John Anderson -

Having a similar issue with the certificate mod in M2.3 - seems like some new instances of the activity, won't generate a certificate. I can see that news rows are written to the certificate_issues table, but no certificate.  It just times out. I get this error with debug on:

 

Fatal error: Maximum execution time of 120 seconds exceeded in C:\inetpub\wwwroot\ecbhintranet\lib\dml\mysqli_native_moodle_database.php on line 902

 

I'm really stuck. I have another site, same code base on the same server, which is running fine with the certificate module. So I guess I have some DB problem? Thanks for any follow up on your fixes...