wordpress转djangoblog语句略记


原计划弄个统一迁移的脚本,想着原来的文章有些也比较乱,就边整理边迁移了,迁移重点语句记录下,以备其他老司机使用。

  1. 文章整体单独迁移,标签和分类整理后迁移(因wordpress有文章重复,需加些条件去重)

    --标签和分类数量不多,人工重新归类添加 --文章迁移

    INSERT INTO `blog_article` (created_time,last_mod_time,title,body,pub_time,status,comment_status,type,views,article_order,author_id,category_id)
        select distinct post_date,post_date,post_title,post_content,post_date,'p','o','a',0,0,1,40 from wp_posts where post_status='publish'
        and post_title not in ('','oracle锁表处理方法');
    
  1. 分类数据迁移(按文章对应分类名称对应)

    --未分类id为40

update blog_article aa set category_id=IFNULL((select e.id from wp_posts d,wp_term_relationships a,wp_terms c,blog_category e
        where d.id=a.object_id and c.name !='未分类' and d.post_title not in ('')
        and c.term_id = a.term_taxonomy_id and c.name=e.name
        and d.post_title=aa.title  limit 1),'40')
  1. 标签数据迁移(按文章对应标签名称写语句迁移)

    --标签入库语句

INSERT into blog_article_tags(article_id,tag_id)
        select distinct e.id,f.id from wp_posts d,wp_term_relationships a,wp_terms c,blog_article e,blog_tag f
        where d.id=a.object_id and c.name !='未分类' and d.post_title not in ('')
        and c.term_id = a.term_taxonomy_id
        and d.post_title=e.title  and c.name=f.name

迁移完成后,大致能看,有些数据由于整理过,还需单个再归类处理,才能完美 呵呵