<p>I would probably do this in two steps:</p>
<ol>
<li>Create a twig file formatted as a CSV that outputs the category and asset id's, i.e.</li>
</ol>
<pre><code>AssetId, Category&lt;br&gt;
{% for entry in entries %}
{{ entry.asset.one().id }}, {% for category in categories %}{{ category.id }}{% if not loop.last %}-|-{% endif %}{% endfor %}&lt;br&gt;
{% endfor %}
</code></pre>
<ol start="2">
<li>Use <a href="https://plugins.craftcms.com/feed-me" rel="nofollow noreferrer">feed me</a> to re-import the categories onto the assets using the CSV.</li>
</ol>

CC BY-SA 4.0
2020-10-23T10:04:40.523Z
Clever! Will try this, thank you!
evvvvritt
CC BY-SA 4.0
2020-10-20T22:00:00.767Z
2020-10-20T22:00:00.767Z
dmatthams
<p>Is it possible to migrate content like categories from an entry to an asset easily?</p>
<p>Each entry has an image asset and I'd like to move all the categories on the entry to the asset.</p>
<p>Would this require a SQL operation or is there any easier way?</p>

<migration>
Migrating categories from Entry to Asset
# Migrating categories from Entry to Asset

(Asked by: username_0 on 2020-10-19)

Is it possible to migrate content like categories from an entry to an asset easily?

Each entry has an image asset and I'd like to move all the categories on the entry to the asset.

Would this require a SQL operation or is there any easier way?

**Tags:** migration

---

## 1 answers

### Answer by username_1 on 2020-10-20. Score: 2 | Accepted answer

I would probably do this in two steps:

Create a twig file formatted as a CSV that outputs the category and asset id's, i.e.

AssetId, Category
{% for entry in entries %}
{{ entry.asset.one().id }}, {% for category in categories %}{{ category.id }}{% if not loop.last %}-|-{% endif %}{% endfor %}
{% endfor %}


Use feed me to re-import the categories onto the assets using the CSV.

> **Comments:**
> **username_0**: Clever! Will try this, thank you!  

---

