Situation : when using MySql scripts to insert (migrate) data to the D7 field structure.

Issue : many columns in field_data_field_[name] and field_revision_field_[name] are considered PRIMARY, which disallows for example to import two rows with the same entity_id (which is really the node id). This is silly since some content type fields will allow many data, like having two documents attached to the same node.

Though those columns are not set to unique in theory, because they are somehow marked Primary, they cannot be doubled.

Tip : do not use the MySql IGNORE option if you do not want to lose field data/files.

Solution or workaround I found : in PhpMyAdmin, I could modify what columns are Primary. In these cases, I chose field_[name]_fid, since fid numbers must be unique.

I am not an expert, but that did slow down my migration process.

nb: on the other hand, adding two rows from a same field from the online CMS worked (publishing an article for example). The table showed two rows with the same entity_id without issues. Therefore, the Primary key issue does not seem to occur when using the online publishing.

ps: which is why the component marked with this issue is Database rather than Field.

Comments

michael_lessard_micles.biz’s picture

Issue summary: View changes
michael_lessard_micles.biz’s picture

Issue summary: View changes

The word not was missing in two sentences.

David_Rothstein’s picture

Category: Bug report » Support request

I'm not sure what you mean here. The columns are not primary keys separately (that isn't possible in SQL; each table can have only one primary key). They are combined together into a single primary key. So nothing stops you from having two rows with the same entity_id as long as one of the other columns that makes up the primary key differs between the two rows.

In the case of your example (a field that has more than one value) the "delta" column is used for that. If there are two documents attached to the same node as part of the same field, both will have the same entity_id but the first has a delta of 0 and the second has a delta of 1.

Hope that makes sense...

michael_lessard_micles.biz’s picture

Thank you for the info about the use of the delta column which should bypass the MySql error about duplicate PRIMARY KEY: I will test MySql import using different delta (but I am not hopeful).

michael_lessard_micles.biz’s picture

Follow-up : after much testing, if the delta number is increased, it does indeed accept a new row with the rest of the data being identical.

My attempts though at MySql scripting delta+1 have failed.

Example - MySql script (not php) :

INSERT INTO field_data_field_term_name
(entity_type, bundle, deleted, entity_id, revision_id, language, delta, field_term_name_tid)
SELECT 'node', 'event', '0', nid, vid, 'und', '0', tid
ON DUPLICATE KEY UPDATE delta = VALUES(delta)+1
FROM old_transferred_D6_table;

Version: 7.38 » 7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

Status: Active » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.