# Move categories with command line

**URL:** https://meta.discourse.org/t/move-categories-with-command-line/138093
**Category:** Self-hosting
**Tags:** rails-console
**Created:** [January 8, 2020, 8:31pm UTC](https://meta.discourse.org/t/move-categories-with-command-line/138093 "2020-01-08T20:31:06Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![ruperty](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ruperty/32/164033_2.png) [@ruperty](https://meta.discourse.org/u/ruperty)
#### Post date: [January 11, 2020, 1:09pm UTC](https://meta.discourse.org/t/move-categories-with-command-line/138093/3 "2020-01-11T13:09:54Z")

</div>

> [@pfaffman](#):
>
> `parent=Category.find_by_slug('slug') subs=Category.where(<a way to get your categories>).update_all(parent_category_id: parent.id)`

Thanks. It took me a while to figure out what was meant by “a way to get your categories”, but realised it probably was the “where” clause of a SQL statement. Though I had no idea what the table names or column names were, but managed to find them with the SQL statements noted in the post about the [Data Model](https://meta.discourse.org/t/databases-data-model/93668/4).

So, I ended up with this,

> `parent=Category.find_by_slug('csgnet') subs=Category.where('slug like “csg1%”').update_all(parent_category_id: parent.id)`

which moves all categories starting with the text “csg1” into the category “csgnet”, where “slug” is the column name in the table of categories. The table name is called “category”, I think.

---

_[View the full topic](https://meta.discourse.org/t/move-categories-with-command-line/138093)._
