I posed this question in the 'Converting to Drupal' sub-forum, but seems like the threads there are mostly targeted by spambots:
https://www.drupal.org/node/2678378

Let me cut to the chase: how do I import prepared content into Drupal 8?

I'd like to convert a games related website to Drupal. Being able to create a Games content type, and then relating Articles back to one or more Games would save me so much time!

But d8 doesn't seem to have an accessible way to import content. Feeds doesn't have a CSV import for d8 (yet), and the documentation I've read about d8_custom_migrate makes my head spin... I spent a half day poking at it but it's just a bit out of reach for me.

Question:
Is there a way for me to define a Content Type in Drupal, export a CSV template, load my content into that CSV, and then load the CSV back into Drupal?

Otherwise, what's the recommended method to get my content into Drupal? I'm itching to get going!

Thanks for your eyes,
-Matt

Comments

Vinoth.m’s picture

Try Feeds module for CSV import.

If you migrate Drupal minor version to Drupal 8, you can do it by drush.

Drush Command :

drush migrate-upgrade --legacy-db-url=mysql://DB_username:DB_password@servername/D6_database d6.yml

Before that you need to create .yml file and place it to drupal root folder.

zolointo’s picture

Like I said, Feeds for d8 doesn't do csv yet. The node page for it indicates that it does, but when you load it into Drupal, it specifically says CSV IMPORT NOT WORKING, DO NOT USE.

:(

And I'm not converting a d6 or d7 site. I have content prepped in CSV files ready to go, but can't figure out how to get it into Drupal.

I explored some of the db tables last night and think I could do a direct inject, but that seems pretty risky without a full comprehension.

Anyone else have advice for CSV import to Drupal 8? Perhaps an expanded tutorial on the migrate CSV module?

zolointo’s picture

Still looking for further assistance.

How do you load content into Drupal?

Thanks again,
-Matt

joegml’s picture

@zolointo I'm using the feeds RSS import painfully, but with multiple runs you can bring in multiple fields. This is a pain, but it seems easier than the recommended migration methods with yaml files, etc.

Importing content should not be this hard in the new and glorious Drupal 8!

Note that I needed the patch listed in https://www.drupal.org/node/2651320#comment-10758744 to make the guid work. See comments there for context.

I believe at this point there is still no csv parser for the feeds importer. I'm hoping it comes soon. Until then, look at the other parser methods I guess.

zolointo’s picture

Funny you responded today. I just started looking at it again yesterday after having shelved my work.

When I last left off, I did manage to get the sample file to import! I was running the drush command in my homedir on my server vs running it in the Drupal site directory.

But yesterday I installed everything from scratch and was trying to activate the migration tools. NOPE. Drupal is now on version 8.1 (vs 8.0 just a while ago) and there's some sort of incompatibility between migrate_tools and the CSV importer.

I'll look at the RSS importer, but I've pretty much given up on Drupal. At my level of comprehension it's just too difficult to get my data in there. It's just nonsensical that I can't create a content type, export an import template, paste my data in there, and import it.

joegml’s picture

Agreed on the "nonsensical" bit! Please keep me posted on your progress and I'll try to update here with mine. I've got an ubercart build and other content I'm trying to migrate from D6 to D8. We can't be the only ones struggling with this. This should not be this hard!

Oh and be careful with versioning. I recommend full backups and git so you can roll yourself back to "where it worked". I'm nervous about updating for that reason.

rukaya’s picture

Have you guys tried the Migrate Source CSV module? https://www.drupal.org/node/2574707

joegml’s picture

I found out client needed to hand curate some of the content, so I abandoned the migration.

This looks reasonable. Why only two comments on that page? I'd definitely try this in the future as it looks fine. But... I'm a bit wary. Like to see more confirmation that this is a simple workable approach.

arla’s picture

I have been using the Migrate API to successfully import CSV, using the migrate_source_csv module. But yes, the Migrate API is very difficult to learn and use.

I have also seen a more direct solution using fgetcsv().

I agree that it's a bit strange that there are no easier methods developed for this. The explanation I think is that the focus has been on migrating from D6 or D7 (without changing any of the structure). If you fit that use case, it's really simple.

nathan tsai’s picture

@Arla,

I was wondering how you achieved this. I'm trying to import a CSV through the migrate source csv module, but don't know where to start.
Thanks!

mrksdiehl’s picture

We (I) want to switch from Wordpress to Drupal. We have years of content and there is no way to import it? I already looked at Drupal 8 last year pre release, now I am back and it is still not possible to import content via csv? Isn't there any good news on this? I want to leave wordpress so badly :...-(((

almaudoh’s picture

There's some useful steps at https://www.drupal.org/docs/8/upgrade/using-the-migrate-source-csv-plugin that specifies how you can import from CSV to D8. I tried it and it works.
Take note that you have to create all the content types first.

joegml’s picture

almaudoh, I guess that looks doable, but jeesh this shouldn't be this hard. In my mind, you should define content types with fields, then align fields to csv columns and zoom, do the csv import and populate nodes. Is there some reason this won't fly in D8?

I can probably figure out the yml file and all the rest that's needed (as shown in the more complicated at https://github.com/heddn/d8_custom_migrate), but this was so much easier in D7.

I've got a large site that's on D6 and needs to migrate with 3000ish nodes w 4 custom content types (one with 10 fields). My decision on D7/D8 will be based on ease of migration.

I migrated the city of Burlington, VT to Drupal 7 a couple of years ago: https://www.burlingtonvt.gov. I used perl to export content from an ailing Ektron CMS and build a series of node_add statements for D7. This is kind of a workaround for a CSV import. I could try this approach in D8 if I found a good reference on "drupal 8 node_add programatically". I see various approaches here, but none seem to be the official sanctioned Way Forward. Looks like more confused developers wandering through the D8 jungle ;-)

joegml’s picture

In the official docs at https://www.drupal.org/docs/8/upgrade/brief-overview-and-history-of-auto...

Personally, I have happily resigned myself to copy/paste my 500+ multi-fielded D7 pages

Really? Really? You have time to do that? My brain would be putty on a plate if I had to do that.
Wondering if any other stragglers have news of progress on this front? Feeds still advertising no csv support for D8 although there seems to be strong interest: https://www.drupal.org/node/2669974#comment-11309369.

Thanx All. Drupalling ever onward.

bmick@arcweb.com’s picture

In case it helps, I have been learning Drupal and Migrate, while extracting content from a SharePoint site into CSV. Have been using Acquia Desktop (8-x-1.04) as an environment to develop .yml configurations. Have a couple of migrations working and here is the process in general (including a couple of details that cost me hours):

1) Load and enable the following modules:
Migrate
Migrate Plus
Migrate Source CSV
Migrate Tools
Note: I also had the following enabled on my dev PC
Migrate Drupal
Migrate Drupal UI

2) Place the CSV file in a folder under files: 'public:///yourCSVs/.csv'

3) In Drupal go to ->> admin/config/development/configuration/single/import
- In configuration type, select "Migration"
- Open .yml in a text editor
- Copy the entire contents and past it in the Migration configuration.
- Click "Import", then "Confirm"

4) Open a Drush consol
- Enter "Drush core-cli"
- Enter "ms" and make sure is there.
- Enter "mi "

5) Should see the number of drupal items created.

6) Can roll back the import by entering "mr "

7) When you need to change the yml, you need insert the uuid in your yml file.
- Go to "Export" (instead of Import), "Single"
- Export the jaml.
- Copy the uuid line and put in file.
- Load it in the migration as before and import it.

where is simply a file name such as "BeersPages.yml"

Notes:
1. Text to text (plain text, body html ...) worked first time.
2. I had to "map" taxonomy names, to Drupal Taxonomy ids in the yml file. If you migrate your taxonomies (I didn't), you can simply use the "migrate" plugin to do the mapping. The taxonomy names (in CSV), must be unique and used as the "key" in the yml file for this to work.
3. Dates get into the database, but do not show up in site pages?
4. Was not successful importing images - did not try hard - easily fixed manually.
5. Have not been successful supplementing this with PHP yet - callbacks would help me.

Hope there is something helpful here.

dhayanandan_k’s picture

Please check this module Content Import

junix33’s picture

I just tried this today. I got an error after hitting import button - "The website encountered an unexpected error. Please try again later."

dhayanandan_k’s picture

Hi,

Can you please check the report and post the error here. I have updated the code in dev. Please try again and also let me know what field types you are using. So that I can fix it and release patch

junix33’s picture

I used the 8.x-3.1 today and it works for me. I tested it with custom content type. I only used the "title", "body", "taxonomy", and "image".
For the image, I can import single image only. Thanks.

dhayanandan_k’s picture

Thanks for using Content Import module

arekstopa’s picture

Hello,
I am using Drupal 8.3.5. I have installed Content Import Ver. 2.
I am not able to get a successful import so far.
I have created a custom content type with just two fields; one Text(plain) and one Number(integer). I have created a sample csv data file with just two rows (plus a title row with the machine names of fields). No matter how I tweak my csv file I am getting consistently the following error: "The website encountered an unexpected error. Please try again later". When I refresh the screen I an error from the Content Import module that says: "The file used in the Import CSV File field may not be referenced."
My csv file contains the following:

title,field_field1,field_field2
record 1,this is the content of field 1,1
record 2,this is another content of field 1,2

I also tried the version with quotes around individual fields, with the same result.
So far I can't figure out where the problem lays . Do you have any suggestions?

Sincerely,
Arek

dhayanandan_k’s picture

Hi @arekstopa,

I have tried the same today, I can able to import the fields smoothly.Today, I have added a feature to support multilingual. We need to specify an additional column "langcode" to specify the node language. Please check the dev version.

I have used below file,

title,langcode,field_field1,field_field2
record 1,en,this is the content of field 1,1
record 2,en,this is another content of field 1,2

Regards,
Dhaya

arekstopa’s picture

Hi Dhaya,
Thank you for you response.
I have installed the new dev version as you suggested, and made the changes to the csv file to account for langcode field.
Unfortunately when I try to run the import I am still getting the same error message:"The file used in the Import CSV File field may not be referenced."
Since you were able to run import successfully, I think that maybe there is some incompatibility between my specific installation (including additional modules in my Drupal installation) and your module.
Are you aware of any additional reasons why I could be getting this particular error?

Thank You,
Arek

zolointo’s picture

I had abandoned Drupal months ago, but seeing this response had me come back to check it out again. Thank you so much for doing this.

I did a simple title+body import with the langcode field set to en, and it worked perfectly.

It's been a while since I've played around in here, so I don't know how easy it is to export a CSV template for different Content types, but how about this?

Feature Request:
After selecting a Content Type, allow the user to export a blank CSV template file with all possible fields.

alagirirajesh’s picture

Hi,

I have tried importing the content to a content type with a long list of fields which did not work. Even after including the title, langcode and a couple of fields added.

Next i tried to create a new content type "simple content" with only the "title" and "body" and the csv is of the following format which did just refresh the page did not import any content. Please let me know if i am doing anything wrong.

title,langcode ,body
content title1,en,content body1
content title2,en,content body2
content title3,en,content body3
content title4,en,content body4
content title5,en,content body5

Also is the "content type" machine name used as the title or the "Title field Label" in the "Submission form settings". And the body is a field that shows up when i open the manage fields tab.

Please advice.

dhayanandan_k’s picture

@alagiriragesh,
I don't know why it is not coming.. Do you face any errors?. Else create a fresh content type and try again. Surely it will work for these fields. Check the file type is CSV, and check if any other extra columns is there. Please validate the file with machine name(spaces, special characters.. everything) and try again.

Thanks,
Dhaya

dhayanandan_k’s picture

@zolointo
Thanks for trying this module. Guess many having some problems to find the machine names. I will add blank CSV template soon. It is good idea to improve the module further. Thanks for your valuable suggestion. Surely I will update the request and release in feature.

logeshvaran’s picture

HI dhayanandha_k

I have used Content Import Module for importing csv file,

Here the module is working fine for all the fields, except geo location field.

I have installed the Geo Location Module, then it will show the lat/long text field. while importing the csv file for the particular content type. All the fields values are stored in respective contents, but the lat/long text fields is alone empty

How could I solve this issue ?

If I solve this issue, then it will be more easier for me to importing csv file.

Please help me !

dhayanandan_k’s picture

@logeshvaran

I have include the Geolocation import in the module. Additionally you can download the sample CSV generated for the selected content type and use the same file to upload. Please check the latest version.

wipeout_dude’s picture

Has anyone god this module to work with Book pages? I just get an error "The website encountered an unexpected error. Please try again later."..

Also when importing a book page does anyone know how to specify the book the page should be part of?

Thanks..