Problem/Motivation
After submitting the user register form, as anonymous user, I get this error "SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '526' for key 'PRIMARY': INSERT INTO multiple_registration".
This happens because the _multiple_registration_rid() is trying to insert a new record in multiple_registration table, but there is already a record that inserted from multiple_registration_update_registration_table().
Steps to reproduce
1) Install and configure Multiple Registration
2) Try, as anonymous user, to insert a new user from the user registration form.
Comments
Comment #3
balis_m commentedThe merge request !4 solves the issue.
Comment #4
ysamoylenko commentedHello @balis_m,
I've tried to create several users from the custom registration page provisioned by this module (In the incognito window, by anonymous user). The multiple_registration table in DB is also was not empty.
Each time, during the debug session I saw a new (unique) value for a user which I want to create (It is related to the place from the code mentioned by you). No errors happen during new user creation in my local environment.
Testing environment: Drupal 9.3.3, multiple_registration 3.x-dev with already applied patch - #3264649: Can not set values on immutable configuration multiple_registration.access_settings_page_form_config:multiple_registration_pages_allowed_list
We need more people to test the problem.
Also, please take a look at this comment:
https://www.drupal.org/project/multiple_registration/issues/3261719#comm...
Maybe it will resolve your issue without patching the module
Comment #5
plessas commentedI will describe my experience with this issue:
I was using v3.0.2 with Drupal 9.3.5. When I tried to update to 3.1.0, running the update script (specifically multiple_registration_update_8204() function) failed due to the integrity constrained violation. Checking my multiple_registration table, I realized that there were several multiple entries for the same uids and as result it was not possible to set uid as a primary key. I deleted the surplus entries and running the update was successful. However, when a user tries to register now, it seems that two identical entries are saved in the table and the second one causes the error. Applying @balis_m solution results in just one entry in the table and no errors. I was not able to find which part of the remaining code saves this entry in the table. I should mention that some users are registering via the SAMLAuth module (for their role i have created a registration form that is hidden) and some other users from their role-specific registration form. However, I don't believe this detail is relevant to the problem.
Comment #6
balis_m commentedHello @ysamoylenko,
I've faced the same issue as described by @plessas.
The
multiple_registration_user_presave()inserts the first entry into themultiple_registrationtable.Then, the
_multiple_registration_rid()tries to insert a new entry with the same uid and causes this error (duplicate entry).So, in the merge request, I've removed the code from
_multiple_registration_rid()as it is not needed anymore.Now,
multiple_registration_user_presave()andmultiple_registration_user_insert()insert the entry into multiple_registration table.Also, I don't think that
multiple_registration_user_insert()is needed too.Comment #7
lamp5I have the same issue during db update.
Comment #8
diego ruiz del árbol commentedSame issue here
Comment #9
sphism commentedSame here multiple_registration_update_8204 fails because there are lots of duplicates in the db so the primary key can't be added... probably needs some code to de-dupliate before it runs that... or maybe uid could just be a key and have a separate pk?
Comment #10
sphism commentedI was just trying to do a mysql de-duplicate but without a primary key I couldn't figure out how to do it, so this script de-duplicates everything in php, then truncates the multiple_registrations table and inserts the clean data... back up the table first since if it goes wrong you could easily wipe your data. But in case anyone else needs this then heres the code. I put it into a drush command.
Comment #11
sphism commentedAfter de duplicating the table I tried registering and got a WSD
Merge request !4 solved it
Comment #12
pappisSame issue here. Drupal core 9.3.6 . Multiple Registration 3.1.0 with patch https://www.drupal.org/project/multiple_registration/issues/3264649
Applied merge request !4 and issue seems resolved.
Comment #13
renrhafI also encountered this issue, I fixed it on my side with the use of an upsert instead of an insert.
What do you think ? I don't know if completely removing this code block like in the merge request won't create any other issue.
Comment #14
renrhafPatch attached if needed.
Comment #15
saki_rayogram commentedApplied above patch 14 and it worked for me. Running Drupal 9.3.7 and version 3.1.1 of this module and have still been getting this error every time I create a user via a multiple registration page. This patch is the only thing that has worked so far. I haven't seen any adverse effects, but haven't tested in depth yet.
Comment #16
osab commentedthe patch 14
didn't help me, unfortunately. Still have:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '8' for key 'PRIMARY': ALTER TABLE "multiple_registration" ADD PRIMARY KEY (`uid`); ArrayComment #17
astoker88 commented@osab have you tried running sphism's code to remove the duplicate entries in your multiple_registration table? Works for me after running this.
Ive deployed it out through a few environments with an update hook like so:
/**
* Delete duplicate rows from multiple_registration table.
*/
function mymodule_update_8001() {
$database = \Drupal::database();
$query = $database->select('multiple_registration', 'mr');
$query->addField('mr', 'uid');
$query->addField('mr', 'rid');
$query->orderBy('mr.uid');
$result = $query->execute();
$clean = [];
if ($result) {
while ($row = $result->fetchAssoc()) {
$clean[$row['uid']] = [
'uid' => $row['uid'],
'rid' => $row['rid'],
];
}
}
if (count($clean)) {
$database->truncate('multiple_registration')->execute();
$query = $database->insert('multiple_registration')->fields(['uid', 'rid']);
foreach ($clean as $record) {
$query->values($record);
}
$query->execute();
}
}
Comment #18
HitbyI'm also still suffering from this. Could you please explain how you used an update hook to run the code in #17. I've tried the patch from #14.
Thanks
Comment #19
renrhafHi @Hitby
You could execute the following command to run the database cleaning :
I just copied the code from https://www.drupal.org/project/multiple_registration/issues/3264902#comm..., please use with caution and make backups if necessary.
Or add a custom update hook in a module like shown in https://www.drupal.org/project/multiple_registration/issues/3264902#comm...
Comment #20
HitbyGreat thank you Renrhaf, that's fixed the issue!
Very much appreciated.
Comment #21
osab commented@astoker88 thank you, I'll check again later. For now its hard to find time because of awful and brutal war Russia against our country Ukraine ((. I've just freeze version on 3.0.2 for a while.
Comment #22
ihor_allin commentedI had the same problem with updating the module to 3.1.0. The solution proposed by @astoker88 worked perfectly for me. Thanks!
Comment #23
uniweb commentedI had the same problem, with D9.3.12 and patch #14 worked for me. Thank you
Comment #24
akkaz commentedCan you commit the patch in #14?
Comment #25
ruiadr commented#14 works like a charm, thx a lot !
Comment #26
sébastien-frpatch #14 works very well.
I had also this issue after creating a user with uid=18 for example :
Comment #27
chikeUsing 9.4.1, I also got the error posted on #26.
Likewise, patch #14 solved the issue.
Comment #28
philyPatch #14 works for me using Drupal 9.4.6 and multiple_registration 3.1.1
Thanks
Moving to RTBC as it seems OK for other reviewers too.
Comment #30
ysamoylenko commentedHello everyone.
Thanks for your solutions and review.
The #14 was committed now to the 3.x branch. The new module release will be published soon. Have a good day.
Comment #32
Narendra@drupalchamp commentedPatch #14 works for me..
Comment #34
megakeegman commentedExtra confirmation that patch #14 is effective
Comment #35
drakegreeott commentedPatch #14 worked for me.
Comment #36
munchmunch commentedi couldn't find this issue referenced in any of the recent releases notes, which release fixed this issue?
Comment #37
stolzenhain commented@munchmunch it was fixed in 3.2.3