# How to create migration files?

**URL:** https://meta.discourse.org/t/how-to-create-migration-files/48991
**Category:** Development
**Created:** [8월 22, 2016, 10:55오전 UTC](https://meta.discourse.org/t/how-to-create-migration-files/48991 "2016-08-22T10:55:12Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![dachary](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dachary/32/119731_2.png) [@dachary](https://meta.discourse.org/u/dachary)
#### Post date: [8월 22, 2016, 10:55오전 UTC](https://meta.discourse.org/t/how-to-create-migration-files/48991/1 "2016-08-22T10:55:12Z")

</div>

I would like to create a new table (to store the graph for vote delegation). Should I create a migration file similar to **db/migrate/20120311170118\_create\_users.rb** manually ? Or is it enough to update the **== Schema Information** at the end of the model file ? I naively tried that and run **rake db:migrate** but it did not work 😉

---

<div class="post-metadata">

### Author: ![Overgrow](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/overgrow/32/478189_2.png) [@Overgrow](https://meta.discourse.org/u/Overgrow)
#### Post date: [8월 22, 2016, 11:43오전 UTC](https://meta.discourse.org/t/how-to-create-migration-files/48991/2 "2016-08-22T11:43:22Z")

</div>

No, you need to create migrate file and run it with db:migrate (see [ActiveRecord docs](http://edgeguides.rubyonrails.org/active_record_migrations.html) )

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [8월 22, 2016, 1:43오후 UTC](https://meta.discourse.org/t/how-to-create-migration-files/48991/3 "2016-08-22T13:43:38Z")

</div>

Note that if you are developing a plugin, discourse provides a PluginStore to help you avoid migrations, since undoing then when the plugin gets uinstalled is a open problem.

---

<div class="post-metadata">

### Author: ![dachary](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dachary/32/119731_2.png) [@dachary](https://meta.discourse.org/u/dachary)
#### Post date: [8월 22, 2016, 1:49오후 UTC](https://meta.discourse.org/t/how-to-create-migration-files/48991/4 "2016-08-22T13:49:55Z")

</div>

> [@Overgrow](#):
>
> No, you need to create migrate file and run it with db:migrate

Thanks, I’m glad I did not miss something 🙂

---

<div class="post-metadata">

### Author: ![dachary](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dachary/32/119731_2.png) [@dachary](https://meta.discourse.org/u/dachary)
#### Post date: [8월 22, 2016, 1:52오후 UTC](https://meta.discourse.org/t/how-to-create-migration-files/48991/5 "2016-08-22T13:52:41Z")

</div>

> [@Falco](#):
>
> discourse provides a PluginStore to help you avoid migrations

cool. Is there a plugin I could read to see how it’s used ? I found [something on rubydoc](http://www.rubydoc.info/github/discourse/discourse/PluginStore).

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [8월 22, 2016, 1:59오후 UTC](https://meta.discourse.org/t/how-to-create-migration-files/48991/6 "2016-08-22T13:59:39Z")

</div>

Canned replies is recent and does it very clearly:

> <https://github.com/discourse/discourse-canned-replies/blob/main/plugin.rb>

---

<div class="post-metadata">

### Author: ![Overgrow](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/overgrow/32/478189_2.png) [@Overgrow](https://meta.discourse.org/u/Overgrow)
#### Post date: [8월 22, 2016, 2:41오후 UTC](https://meta.discourse.org/t/how-to-create-migration-files/48991/7 "2016-08-22T14:41:12Z")

</div>

> [@Falco](#):
>
> Note that if you are developing a plugin, discourse provides a PluginStore to help you avoid migrations, since undoing then when the plugin gets uinstalled is a open problem.

OK, thanks… I see …

 ![](https://global.discourse-cdn.com/meta/original/3X/e/a/ead027d58f84bd3775530111c3631f709842de94.png)
