# Two tables in one migration file?

**URL:** <https://www.ruby-forum.com/t/two-tables-in-one-migration-file/189224>\
**Category:** Rails\
**Created:** [May 27, 2010, 4:28am UTC](https://www.ruby-forum.com/t/two-tables-in-one-migration-file/189224 "2010-05-27T04:28:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nirosh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ce7236/32.png) [@nirosh](https://www.ruby-forum.com/u/nirosh)\
**Post date:** [May 27, 2010, 4:28am UTC](https://www.ruby-forum.com/t/two-tables-in-one-migration-file/189224/1 "2010-05-27T04:28:52Z")

</div>

i already have 10\_create\_comments migration file.  
that file contains  
create\_table :comments do |t|  
t.column :title, :text  
t.column :foto\_id, :integer  
t.column :user\_id, :integer  
t.column :created\_at, :datetime  
t.column :updated\_at, :datetime  
end

this is design for photo commenting purpose. i i need another comment  
setup under the message so how do i use this migration file to that?  
any ideas?

nirosh

---

<div class="post-metadata">

**Author:** ![nirosh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ce7236/32.png) [@nirosh](https://www.ruby-forum.com/u/nirosh)\
**Post date:** [May 27, 2010, 6:11am UTC](https://www.ruby-forum.com/t/two-tables-in-one-migration-file/189224/2 "2010-05-27T06:11:02Z")

</div>

Your current create\_table should appear in the self.up section of the  
migration… self.down should undo any operation that self.up performs  
(where reasonable).

There’s nothing stopping you from adding another create\_table statement  
as long as its properly formatted.

You’ll probably hear all sorts of opinions about mixing more than one  
action in a single migration step. If you do create more than one  
table, realize that the migration becomes an all or nothing choice, both  
tables or neither.

You can code it however you want of course, but what is so bad about  
adding another migration for the message comments?

From my point of view, what you really want is a polymorphic join  
between comments and several (at least two) other models in your  
application. Check out has\_many\_polymorphs, and simplify your  
development.
