# Generate a migration file

**URL:** <https://www.ruby-forum.com/t/generate-a-migration-file/196749>\
**Category:** Rails\
**Created:** [July 20, 2008, 2:24pm UTC](https://www.ruby-forum.com/t/generate-a-migration-file/196749 "2008-07-20T14:24:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![z4n9ief](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/7993a0/32.png) [@z4n9ief](https://www.ruby-forum.com/u/z4n9ief)\
**Post date:** [July 20, 2008, 2:24pm UTC](https://www.ruby-forum.com/t/generate-a-migration-file/196749/1 "2008-07-20T14:24:21Z")

</div>

Hi everybody,

I had generated some migrations files such as  
“20080719111013\_create\_countries.rb” for “countries” table :

class CreateCountries \< ActiveRecord::Migration  
def self.up  
create\_table :countries, :force =\> true do |t|  
t.string :name, :null =\> false, :limit =\> 80  
end  
end

def self.down  
drop\_table :countries  
end  
end

And now I would like to generate a new file migration for  
“arts\_countries” table. But I don’t know how to write the nice command  
with the right convention because this table is composed by arts and  
countries tables (so there isn’t any model)…

Thanks for every ideas.  
Zhang’

---

<div class="post-metadata">

**Author:** ![z4n9ief](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/7993a0/32.png) [@z4n9ief](https://www.ruby-forum.com/u/z4n9ief)\
**Post date:** [July 20, 2008, 2:50pm UTC](https://www.ruby-forum.com/t/generate-a-migration-file/196749/2 "2008-07-20T14:50:17Z")

</div>

Zangief I. wrote:

> … I would like to generate a new file migration for  
> “arts\_countries” table…
> 
> Thanks for every ideas.  
> Zhang’

ruby script/generate migration CreateArtsCountries

but,  
really,  
I’d probably create a model too.

ruby script/generate model ArtsCountries art\_id:integer  
country\_id:integer

---

<div class="post-metadata">

**Author:** ![z4n9ief](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/7993a0/32.png) [@z4n9ief](https://www.ruby-forum.com/u/z4n9ief)\
**Post date:** [July 20, 2008, 3:07pm UTC](https://www.ruby-forum.com/t/generate-a-migration-file/196749/3 "2008-07-20T15:07:12Z")

</div>

Hi –

On Sun, 20 Jul 2008, Matthew R. Jacobs wrote:

> but,  
> really,  
> I’d probably create a model too.
> 
> ruby script/generate model ArtsCountries art\_id:integer  
> country\_id:integer

I definitely wouldn’t. Those habtm tables really aren’t supposed to be  
modeled on the Ruby side. There’s no such thing as “an ArtsCountries”.

David

–  
Rails training from David A. Black and Ruby Power and Light:  
Intro to Ruby on Rails July 21-24 Edison, NJ  
Advancing With Rails August 18-21 Edison, NJ  
See [http://www.rubypal.com](http://www.rubypal.com) for details and updates!

---

<div class="post-metadata">

**Author:** ![z4n9ief](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/7993a0/32.png) [@z4n9ief](https://www.ruby-forum.com/u/z4n9ief)\
**Post date:** [July 20, 2008, 6:27pm UTC](https://www.ruby-forum.com/t/generate-a-migration-file/196749/4 "2008-07-20T18:27:21Z")

</div>

David A. Black wrote:

> Hi –
> 
> On Sun, 20 Jul 2008, Matthew R. Jacobs wrote:
> 
> > but,  
> > really,  
> > I’d probably create a model too.
> > 
> > ruby script/generate model ArtsCountries art\_id:integer  
> > country\_id:integer
> 
> I definitely wouldn’t. Those habtm tables really aren’t supposed to be  
> modeled on the Ruby side. There’s no such thing as “an ArtsCountries”.

But that’s probably just a reason to choose a better name.  
But given I don’t know what Arts we’re talking about, I can’t suggest  
one.

In my experience, most things that start off being a  
has\_and\_belongs\_to\_many end up becoming a has\_many :through,  
and as such, already having a well named join in beneficial.

---

<div class="post-metadata">

**Author:** ![z4n9ief](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/7993a0/32.png) [@z4n9ief](https://www.ruby-forum.com/u/z4n9ief)\
**Post date:** [July 20, 2008, 3:34pm UTC](https://www.ruby-forum.com/t/generate-a-migration-file/196749/5 "2008-07-20T15:34:42Z")

</div>

Thanks! That working perfectly 🙂

---

<div class="post-metadata">

**Author:** ![z4n9ief](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/7993a0/32.png) [@z4n9ief](https://www.ruby-forum.com/u/z4n9ief)\
**Post date:** [July 20, 2008, 11:34pm UTC](https://www.ruby-forum.com/t/generate-a-migration-file/196749/6 "2008-07-20T23:34:54Z")

</div>

Hi –

On Sun, 20 Jul 2008, Matthew R. Jacobs wrote:

> > > ruby script/generate model ArtsCountries art\_id:integer  
> > > has\_and\_belongs\_to\_many end up becoming a has\_many :through,  
> > > and as such, already having a well named join in beneficial.

Of course if you want to create a model and do :through, that’s fine.  
I was referring specifically to habtm tables, which should not be  
modeled.

David

–  
Rails training from David A. Black and Ruby Power and Light:  
Intro to Ruby on Rails July 21-24 Edison, NJ

- Advancing With Rails August 18-21 Edison, NJ
- Co-taught by D.A. Black and Erik Kastner  
See [http://www.rubypal.com](http://www.rubypal.com) for details and updates!
