Problem/Motivation

When running drush convert-field-collection I am getting:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'node-2711-0-0-und' for key 'PRIMARY': INSERT INTO ...

I am not sure what is causing this yet.

Proposed resolution

I am looking into this now but figured I would post this here to get some more attention.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

Elijah Lynn created an issue. See original summary.

elijah lynn’s picture

Possibly related to #2327317: Integrity constraint violation when saving multifield with a file subfield but I don't think so because the errors are different. The field collection in question does have an image field.

elijah lynn’s picture

I should note also that this is happening on two different field collections. One has an image and the other one doesn't. I don't think it is related but I will leave it linked I suppose, just in case.

elijah lynn’s picture

Issue summary: View changes
StatusFileSize
new20.66 KB

So it does appear that the primary key combo does exist already and when we do a drupal_write_record($table, $record) in drush_multifield_convert_field_collection_table() we are trying to insert a new record, not update an existing one.

elijah lynn’s picture

Title: PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'node-2711-0-0-und' for key 'PRIMARY': INSERT INTO » drush convert-field-collection - PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'node-2711-0-0-und' for key 'PRIMARY': INSERT INTO
elijah lynn’s picture

After reading through #2534348: multifield_get_next_id is brittle I feel like this is probably the solution.

elijah lynn’s picture

So it actually appears that it only happens when there are 2 or more batches. I have 4 field collections the two that succeed are under 100 field collections. The two that fail are ~1,500 and ~3,000 entries.

While in xdebug, the second set tries to drupal_write_record() the same set the second time, therefore making duplicates. Still investigating.

elijah lynn’s picture

I removed drush_backend_batch_process(); from multifield.drush.inc (line 122) to let the normal batch process do its thing and it got rid of this error and the conversion was successful! I think the multiple processes were not aware of where the other processes were. Haven't had time to look into how to make this actually work but wanted to post this feedback.

elijah lynn’s picture

Lol, I guess I was thinking that it would use normal batch_process() if it wasn't specified because I think the Form API does that for forms. I am back to figuring out why the multiple processes are calling the same duplicate nid.

elijah lynn’s picture

Alrighty, here is what I came up with but I am not sure how this is possible because I would think this is affecting everyone who does a drush migration from Field Collections but maybe not that many people use that?

On line 148 of multifield.drush.inc it is using the 'offset' but I don't see where that is declared. I changed it to 'count', which makes more sense and returns different records as is expected:


$query->range($context['sandbox']['offset'], 100);

I'll post a patch soon but this appears to fix the issue.


$query->range($context['sandbox']['count'], 100);

elijah lynn’s picture

Status: Active » Needs review
StatusFileSize
new630 bytes

dave reid’s picture

Status: Needs review » Fixed

D'oh! Committed to 7.x-1.x, thanks Elijah!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.