I've read through the other posts where the suggestion is to set the Widget Type on the Node Reference field to Select List. That fix doesn't seem to work in this case.

I have a list of WorkGroups already loaded into their own content type. My goal is to import all the members. In the Member Content type I created a field called mbr_link and assigned it a type of Node Reference.

I've attempted to import both the Name and NID with the same result:

Widget Type: Autocomplete Tedt Field
I get the following error: mbr_link: found no valid post with that title.

Widget Type: Select List
The mbr_link field is left empty on the first entry, if a person had a second entry it would assign them to the first group (node/1) regardless of the value in the field.

Widget Type: Check boxes/radio buttons
The mbr_link field is populated with the information from the first group (node/1). If the person is a member of multiple groups the first group is listed a second time.

The error data from when the Node Reference field type is Autocomplete shows that the data is being found...
Here's the raw Data:
[type] => workgroup_member
[cck:field_wgm_raw_wg:value] => Array
(
[0] => Advanced Security||Security
)

And here's the node values it determines based on the two groups
[field_wgm_wg_mbr_link] => Array
(
[0] => Array
(
[nid] => Array
(
[nid] => 51
)
)
[1] => Array
(
[nid] => Array
(
[nid] => 925
)
)
)

node/51 is the Security group (workgroup content type)
node/925 is the Advanced Security group (workgroup content type)

Ive attached the entire debug output

Any ideas on how I can fix this issue?

CommentFileSizeAuthor
drupal_node_import_bug.txt3 KBVinceV
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

gjmokcb’s picture

I am (finally) successfully importing data that includes a node reference field. I will tell you how. Hold on, this is easier than it sounds at first. I provide lots of detail because you have to do it just right.

I use the Table Wizard module and the Migrate module, not the Node Import module.

I set my node reference field to the autocomplete widget type. Now assume that you have a node titled "one" with an NID of "13452." When you upload, remember that the Drupal database does not want to know "one," even though that is what you would enter in the input field as a user. The database wants to know the NID of the node you are referring to: "13452."

You are uploading directly from your desktop to the database. You are bypassing the data entry form. Thus it is the node NID, not the node title that you must upload.

If, being human, you can recognize your node-reference node titles, but have not memorized their NIDs, then you need to create a table (or spreadsheet) that matches the title to the NID.

In my case, I am uploading a list of product UPCs (barcode numbers) and prices provided to me by vendors. I have already created product nodes in Drupal, with UPCs as node titles. Each product node has the product's name and some other info, but does not have the price--the vendor's spreadsheet determines the price, which changes from time to time. Of course, each product node also has an NID, which is not readily visible.

As mentioned above, we're going to upload the NID (which I don't recognize), not the UPC (which I also don't recognize), or the product's name (which I do recognize). I need to match the unrecognizable UPC on the vendor's spreadsheet with an unrecognizable NID, which Drupal will then match to the unrecognizable NID on the product node for the product with the same unrecognizable UPC. Whew!

The spreadsheet that I get from the vendor (with hundreds of UPCs) does not have the related NIDs. So I have to match the UPC and price from the vendor with the UPC and description in Drupal nodes.

I take the spreadsheet of UPCs from the vendor, with prices. Each line will become a new price node, and each node will have a node reference field that ties to the existing product node. To the vendor's spreadsheet I add a column with a node title for each line item. For new node titles I just use a data series such as vendorname001, vendorname002, vendorname003, etc. Easy to create in Excel. (You could use the same name for each line item, but we're going to make the node title the primary key in a MySQL table, so each line item needs a unique name.)

In Drupal, I create a View (table format) of the already-existing product-node titles (their UPCs) and their matching NIDs. I create an XLS-type feed for the view. I download the view table as an XLS spreadsheet. The result is two columns--UPC and matching NID.

Now I have one spreadsheet that is UPCs, prices, and new node titles, and a second spreadsheet (actually, a second worksheet) that is UPCs and NIDs. The UPCs in the first spreadsheet are usually a subset of those in the second spreadsheet--not every vendor carries every UPC--thus there is more work to be done in matching UPCs and pulling out the right NID.

I use the Excel OFFSET and MATCH functions in a cell of the vendor's spreadsheet of UPCs and prices to refer to the spreadsheet of UPCs and NIDs and grab the right NID. Now my vendor spreadsheet has UPC, price, new node title, and node-reference NID (referring to the product node).

At this point I could delete the UPC column from the spreadsheet--I don't need it anymore.

I upload that spreadsheet with Table Wizard. That creates a new table in the database that serves only as a data source for the Migrate module to use. I go into PHPMyAdmin to designate the node title as the primary key for the new table (this is important!) then return to Table Wizard to export a Views definition. Then I go to the Migrate module, which moves the data from the new table into new nodes, matching the fields in the table to the correct fields in the new nodes. I match the NID column in the spreadsheet to the UPC node-reference field in the nodes.

Poof! New nodes that display the UPC (not the concealed NID) in the node reference field!

Amazing. And it only took two days to figure out.

gjmokcb’s picture

I have confirmed that this technique does not work with Node Import module. It refuses to accept either the title of the node reference or the NID of the node reference. Apparenly, one must use the more complex process of Table Wizard and Migrate.

David Lesieur’s picture

Version: 6.x-1.0-rc4 » 6.x-1.x-dev

Actually, I got Node import working with node references, using titles to define the references. It should also work with nids. However, there is a condition for this to work: The nodes being referenced must exist prior to the import.

Vacilando’s picture

I wonder about this assertion:

The nodes being referenced must exist prior to the import.

I am getting "Input error: John Doe is not allowed for Pupil (not a node reference)" even though there is an entry in the import file for "John Doe". Does the "John Doe" entry have to exist in the database prior to import?

Do you know whether it is a bug or a prerequisite of Node Import? (I have to import a table where fields refer to titles of other entries in the same table (content type).)

David Lesieur’s picture

Does the "John Doe" entry have to exist in the database prior to import?

Good question... Unfortunately, I don't quite remember the answer, but it should be relatively easy to test.

Do you know whether it is a bug or a prerequisite of Node Import?

At the moment, I'd consider this more like a prerequisite than a bug, because Node Import does not pretend anywhere being able to reference not-yet-existing nodes during an import. To do this properly, it would probably have to resolve the references only after having created the nodes.

mollyavalon’s picture

I have the same problem. The referenced node already exists, but Node Import gives this error: Session ID ref: this post can't be referenced.
(Session ID ref is my node reference field)

MortenP’s picture

In my case it actually finds the NID from the Node title, but still gives the error. This is the field, given in my csv file as title:

[cck:field_virksomhed:nid] => Array
(
[0] => 543
)

It has found the correct node id 543, but still throws the error "found no valid post with that title".

It has found another referenced id by title (cck:field_kursustype:nid) without reporting any error, which makes it even more mystifying.

So everything looks fine, but still refuses to import the records.

---------------------------------

Virksomhed: found no valid post with that title.
values = Array
(
[created] =>
[node_import_build_mode] => 1
[title] => Udvikling 1
[cck:field_kursustype:nid] => Array
(
[0] => 1401
)

[cck:field_tilmeldte:value] => Array
(
[0] => 3
)

[og_groups] => Array
(
[39] => 1
)

[cck:field_virksomhed:nid] => Array
(
[0] => 543
)

[cck:field_kursudato:value] => Array
(
)

[cck:field_bilagsdato:value] => Array
(
[0] => 2010-05-23T00:00:00
)

[cck:field_medfinansiering:value] => Array
(
[0] => 16875
)

[type] => kursus
[cck:field_deltagere:value] => Array
(
[0] => 1
)

[body] =>
[format] => 1
[language] =>
[log] => Imported with node_import.
[uid] => 6
[revision] => 0
[status] => 1
[promote] => 0
[sticky] => 0
[comment] => 0
[path] =>
[name] => import
[taxonomy] => Array
(
)

[field_kursustype] => Array
(
[0] => Array
(
[nid] => 1401
)

)

[field_tilmeldte] => Array
(
[0] => Array
(
[value] => 3
)

)

[field_virksomhed] => Array
(
[0] => Array
(
[nid] => Array
(
[nid] => 543
)

)
.......

EDIT:

By changing fields to list instead of autocomplete I got around the error. It's easy enough to change them back to autocomplete once the files have been imported.

herkimer’s picture

Thank you!

--this fixed the same issue for me.

tinflute’s picture

Herkimer, can you clarify the procedure you used to import node reference fields?
Was it required to have nodes created before importing references to them?
Did you create references from nid or from node title?
Some details would be greatly appreciated.
~

hovel’s picture