# Why are schema.rb, migrations, models separated?

**URL:** <https://www.ruby-forum.com/t/why-are-schema-rb-migrations-models-separated/146941>\
**Category:** Rails\
**Created:** [August 27, 2008, 12:12am UTC](https://www.ruby-forum.com/t/why-are-schema-rb-migrations-models-separated/146941 "2008-08-27T00:12:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![klauer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/2acd7d/32.png) [@klauer](https://www.ruby-forum.com/u/klauer)\
**Post date:** [August 27, 2008, 12:12am UTC](https://www.ruby-forum.com/t/why-are-schema-rb-migrations-models-separated/146941/1 "2008-08-27T00:12:42Z")

</div>

Long story short: I’ve been looking at Grails and noticed their models  
contain both the schema information as well as the normal validation,  
constraint information.

Does doing it that way pose some serious deficiencies? I find that I  
get confused with schemas being in an entirely different location than  
the constraints and validation of them.

---

<div class="post-metadata">

**Author:** ![klauer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/2acd7d/32.png) [@klauer](https://www.ruby-forum.com/u/klauer)\
**Post date:** [August 27, 2008, 12:47am UTC](https://www.ruby-forum.com/t/why-are-schema-rb-migrations-models-separated/146941/2 "2008-08-27T00:47:48Z")

</div>

It is the way it is. 🙂

Well that’s not very helpful at all, is it? In all seriousness, the main  
thing you should realize is that a model in Rails looks at an existing  
table  
and builds methods to access the columns in your table. You don’t need a  
migration / schema to have a model.

Migrations in Rails are there to build the database for you but once  
that’s  
done, nothing in Rails ever looks at them again. They’re more of a  
utility  
than anything else.

Other ORM libraries, notably DataMapper, take an approach similar to the  
one  
you describe in Grails. ActiveRecord, however, prefers minimal  
configuration. Also, you might be interested to know that Migrations  
were  
not introduced until Rails 1.1.

If you get confused, there’s a wonderful plugin called annotate\_models  
that  
I use on all my projects. It puts the schema info as comments in your  
models  
and fxtures so you have them as a reference as well as in your docs.

---

<div class="post-metadata">

**Author:** ![klauer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/2acd7d/32.png) [@klauer](https://www.ruby-forum.com/u/klauer)\
**Post date:** [August 27, 2008, 10:49pm UTC](https://www.ruby-forum.com/t/why-are-schema-rb-migrations-models-separated/146941/3 "2008-08-27T22:49:07Z")

</div>

I’ll definitely be checking out the annotate\_models plugin. I  
remember briefly looking at DataMapper, but I haven’t tried doing  
anything in it.

Thank you very much. 🙂
