• I am trying to import a database table (posts) into an existing wordpress database, that already has posts in it. It is of course causing a duplicate entry error. I tried manually changing the id’s but no go. Is there an easy way to do this? I have 400 posts.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hmm… well, you might be running into integrity constraints with some of the other columns. Are you importing from another WordPress installation or another blogging/CMS system? Probably the safest way to go about this would be to use the Import feature built in to WordPress. The feature takes in a WordPress XML file or RSS feed (or sometimes native data formats from other CMS tools… a full list is available from the Import menu) and creates the posts for you in the system.

    If you’re having trouble using the import feature, either because the data size is too large or it’s taking too long to process, try breaking up your content into more manageable chunks of 20-50 posts at a time per data file, then import the files one by one. This may take a little while, but it’s probably the most straightforward way to get your content into WordPress without database errors.

    Alternatively, if the import feature won’t work for you, the other option would be to roll your own import tool, probably as a plugin. That way, you can crawl the content from your old database and use wp_insert_post to add the posts into WordPress.

    I hope this helps!

    Thread Starter webmaster in texas

    (@webmaster-in-texas)

    the problem is, we changed the nameservers from the old host, to the new host. The old site was Drupal, we didn’t know the client also had a Wordpess running their blog, so now a week later we are trying to bring in all these articles, and there are already ID’s established with the pages/posts in the new site.
    There is nowhere to import from. I guess we could change the nameservers back, export, then import again, unless you can import from a sql file.

    Ahh, ok, I see the issue. Well… if all you’re doing is retrieving the content to be migrated over from Drupal to WordPress, and you have a fair understanding of how Drupal’s data is structured, you probably don’t need access to the old server… just the backup data. You could either…

    • Deploy Drupal’s engine and data to a staging environment under your control from backup, then export as RSS. This can be on your local machine (XAMPP’s good for this) or a staging sandbox set up on your remote server. Note that as the URL will have likely changed, you might need to change a couple of settings in your staging DB to reflect this. Unfortunately, I don’t have that much experience with Drupal, so I’m not sure what settings you’d want to change exactly, but as a example from WordPress, when moving data from staging server to staging server, settings like site_url in wp_options needs to be changed (otherwise the links WordPress generates would point to the old site URL).
    • Deploy the database only to a staging environment (for safety’s sake, I’d recommend a different database and db user from production if possible) and write a custom plugin/script as mentioned above to parse the data and import it into WordPress. Or, you could write the script to read the database and create an RSS feed (or feeds).

    The goal here is not necessarily to get Drupal running again in any publicly available sense, but to find a way to transform the data from SQL or Drupal form into something WordPress can understand (RSS) or query (a database that WordPress can reach).

    I hope this helps!

    Thread Starter webmaster in texas

    (@webmaster-in-texas)

    Thanks, we got the info from Drupal fine with the original deployment, it was the wordpress they had running on their server we missed. That site is now down, because we changed the nameservers, so we have the database,and that’s it.
    I simply need to add the posts from the old one to the new one, without getting duplication on the primary ids.
    As far as writing a plugin, I wouldn’t know what to do there.

    Mhmm… ok, so you have the Drupal database backed up and need to move the posts from that database into WordPress. As long as you have the SQL data from Drupal, you don’t need the old server… we just need some way to translate the old Drupal data into something WordPress can understand. WordPress can import posts from an RSS file (doesn’t have to be a live feed), so by transforming the Drupal SQL data into a set of RSS feeds using some sort of custom script (the languages and tech used for this data transformation are developer’s choice), we can use the RSS Import tool built in to WordPress to add the posts. (In retrospect, writing a full plugin might be a little heavy handed for this situation… sorry. Probably would be better going the RSS route.)

    Perhaps I’m partial to a solution that uses WordPress because I’d rather have the WP engine handle the heavy lifting on making sure the posts get imported in working order, rather than muck about with the database. But perhaps another solution would be to match the Drupal data to the structure of WordPress’s database, then modify the post IDs to a high enough number set that they aren’t conflicting with WordPress. The wp_posts table uses auto_increment, so you should be able to easily find out the highest post number and start modifying the posts from Drupal so they’re n+1 to n+1+x, rather than 1-n, and then set the auto_increment value for the table to n+2+x. Haven’t done this method before, so I’m afraid I wouldn’t be able to provide much advice beyond that. =/

    I hope this helps!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to import posts db table into existing db’ is closed to new replies.