# Auto-generate database schema based upon model?

**URL:** <https://www.ruby-forum.com/t/auto-generate-database-schema-based-upon-model/82873>\
**Category:** Rails\
**Created:** [January 22, 2007, 1:40am UTC](https://www.ruby-forum.com/t/auto-generate-database-schema-based-upon-model/82873 "2007-01-22T01:40:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rhodebump](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f6c823/32.png) [@rhodebump](https://www.ruby-forum.com/u/rhodebump)\
**Post date:** [January 22, 2007, 1:40am UTC](https://www.ruby-forum.com/t/auto-generate-database-schema-based-upon-model/82873/1 "2007-01-22T01:40:33Z")

</div>

> From my research, it appears that I have to manually create database  
> tables. I was wondering if there is a gem or something else in ROR  
> that would auto-create the database for me based upon my ruby model.

Thanks.

---

<div class="post-metadata">

**Author:** ![rhodebump](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f6c823/32.png) [@rhodebump](https://www.ruby-forum.com/u/rhodebump)\
**Post date:** [January 22, 2007, 3:31am UTC](https://www.ruby-forum.com/t/auto-generate-database-schema-based-upon-model/82873/2 "2007-01-22T03:31:43Z")

</div>

The fields themselves won’t be auto created, but when you do  
./script/generate model model\_name, you’ll also get a db migration file  
generated for ya.

---

<div class="post-metadata">

**Author:** ![rhodebump](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f6c823/32.png) [@rhodebump](https://www.ruby-forum.com/u/rhodebump)\
**Post date:** [January 22, 2007, 2:13pm UTC](https://www.ruby-forum.com/t/auto-generate-database-schema-based-upon-model/82873/3 "2007-01-22T14:13:47Z")

</div>

You have to manually create the empty db yourself (eg mysqladmin create  
foo\_development)

When you generate the model an empty migration is created in  
db\migrate. Edit this to define the table columns and then run rake  
db:migrate.

Read about migrations, much nicer than hand coding sql scripts.
