def create_categories(apps, schema_editor):
    """
    Copy all PublicBodyTags to Categories
    """
    from ..models import Category, TaggedPublicBody
    categories = {}
    for tpb in TaggedPublicBody.objects.all():
        if tpb.tag.slug in categories:
            category = categories[tpb.tag.slug]
        else:
            category = Category.add_root(name=tpb.tag.name, slug=tpb.tag.
                slug, is_topic=tpb.tag.is_topic)
            categories[tpb.tag.slug] = category
        pb = tpb.content_object
        pb.categories.add(category)
