How to import custom fields along with standard fields for users and/or nodes.

Events happening in the community are now at Drupal community events on www.drupal.org.
wsgarvey's picture

Doing a migration to Drupal 7 from another CMS and trying to import content and users. Can import basic fields just fine, but custom fields aren't working. Tried two ways: direct to MySql database and using drupal cmds.

(1) using sql insert

"INSERT INTO users (name, mail, uid, pass, ...) VALUES (blah, blah, blah, blah, ...), (...); " -- works great. able to login with old user id and password (pass is pre-hashed by Drupal routine).

"INSERT INTO field_data_field_display_name (field_display_name_value, entity_type, bundle, entity_id, revision_id, delta) VALUES (...); " -- insert for custom field "display_name" -- does not work, but if I inspect the table entry right after insert stmt and again after logging in and setting the variable through drupal, the entries are identical.

It appears that entering the custom field value through Drupal, sets the table value AND caches the value elsewhere. That caching (if that is what is happening) is not being done with the SQL inserts. I tried clearing the cache with Drupal, but didn't seem to work. Also tried adding to revisions tables as well.

(2) using php/drupal

$entry = array("name"=>"blah", "pass"=>"blah", ..., "display_name"=>"blah");
createUserAccount($entry);

Again, the user account is created, but the custom field entries are not.

HOW DO I import the custom fields? Thanks.

Comments

Have you tried using the

darora's picture

Have you tried using the Migrate module? It should help you with your needs.

Yes a couple of weeks ago --

wsgarvey's picture

Yes a couple of weeks ago -- it said it was for Drupal 6 only and when i tried it anyway there were several dependent modules that wouldn't install in Drupal 7.

I just looked again and there is now a Migrate V2 that indicates it should work on Drupal 7. I am trying it now.

Thanks.

I've spent the better part of

wsgarvey's picture

I've spent the better part of a day trying to get this installed. One of the attempts:

Migrate
• Error installing / updating
• File Transfer failed, reason: /_Documents/_Projects/EDTU-drupal/site/sites/all/modules is outside of
the /_Documents/_Projects/EDTU-drupal/site

Does anyone know what drupal command or method to update fields? Or what database update to do?

User Record Creation (D7)

jlihnarop's picture

If you want to create manually a user record (in D7), try something along the following lines:

$user = new stdClass();
$user->name='samplename';
$user->pass='samplepass';
$user->mail='samplemail';
$user->status=1;
$user->signature_format='filtered_html';
$user->language='en';
$user->field_user_mycustomfield1['en'][0]['value']='sampledata1';
$user->field_user_mycustomfield2['en'][0]['value']='sampledata2';
$user->roles='sampleroles';
user_save($user);

Content migration, import, and export

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week