# whats wrong with this migration

**URL:** <https://discuss.rubyonrails.org/t/whats-wrong-with-this-migration/65525>\
**Category:** rubyonrails-talk\
**Created:** [October 23, 2012, 2:49pm UTC](https://discuss.rubyonrails.org/t/whats-wrong-with-this-migration/65525 "2012-10-23T14:49:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roelof\_Wobben](https://avatars.discourse-cdn.com/v4/letter/r/e99b99/32.png) [@Roelof\_Wobben](https://discuss.rubyonrails.org/u/Roelof_Wobben)\
**Post date:** [October 23, 2012, 2:49pm UTC](https://discuss.rubyonrails.org/t/whats-wrong-with-this-migration/65525/1 "2012-10-23T14:49:44Z")

</div>

Hello,

I try to add a column named id\_category to my database table berichten. So I have this :

class Bericht \< ActiveRecord::Migration def up add\_column :berichten do [t] t.column :name, ‘id\_category’ end end def down end end

But I get wrong number ( 1 of 3 ) error message.

Can anyone tell me what’s wrong here so I can learn to write my own migrations.

Roelof

---

<div class="post-metadata">

**Author:** ![BalaRaju\_Vankala](https://avatars.discourse-cdn.com/v4/letter/b/9fc348/32.png) [@BalaRaju\_Vankala](https://discuss.rubyonrails.org/u/BalaRaju_Vankala)\
**Post date:** [October 23, 2012, 2:56pm UTC](https://discuss.rubyonrails.org/t/whats-wrong-with-this-migration/65525/2 "2012-10-23T14:56:14Z")

</div>

you have to create a new migration for add\_column

using rails g migration col\_name\_table\_name

in that migration file you have to follow below syntax

def up add\_column : table\_name, column\_name, data\_type

end

i hope its help to you…

---

<div class="post-metadata">

**Author:** ![Roelof\_Wobben](https://avatars.discourse-cdn.com/v4/letter/r/e99b99/32.png) [@Roelof\_Wobben](https://discuss.rubyonrails.org/u/Roelof_Wobben)\
**Post date:** [October 23, 2012, 3:03pm UTC](https://discuss.rubyonrails.org/t/whats-wrong-with-this-migration/65525/3 "2012-10-23T15:03:29Z")

</div>

Sorry I dont help me

I did rails g migration id\_category bericht And changed the migration file to this

class IdCategory \< ActiveRecord::Migration def up add\_column :bericht, id\_category, number end

def down end end

After that I did rake db:migrate and get this output :

== IdCategory: migrating ===================================================== – id\_category() rake aborted! An error has occurred, this and all later migrations canceled:

undefined local variable or method `id\_category’ for #IdCategory:0x00000004c3f0d8

Tasks: TOP =\> db:migrate (See full trace by running task with --trace)

Roelof

---

<div class="post-metadata">

**Author:** ![Roelof\_Wobben](https://avatars.discourse-cdn.com/v4/letter/r/e99b99/32.png) [@Roelof\_Wobben](https://discuss.rubyonrails.org/u/Roelof_Wobben)\
**Post date:** [October 23, 2012, 3:04pm UTC](https://discuss.rubyonrails.org/t/whats-wrong-with-this-migration/65525/4 "2012-10-23T15:04:25Z")

</div>

> > you have to create a new migration for add\_column

> > using rails g migration col\_name\_table\_name

> > in that migration file you have to follow below syntax

> >

> >

> > def up add\_column : table\_name, column\_name, data\_type

> > end
> > 
> > i hope its help to you…

> > > Hello,
> > > 
> > > I try to add a column named id\_category to my database table berichten. So I have this :
> > > 
> > > class Bericht \< ActiveRecord::Migration
> > > 
> > > def up add\_column :berichten do [t] t.column :name, ‘id\_category’ end end def down end end
> > > 
> > > But I get wrong number ( 1 of 3 ) error message.
> > > 
> > > Can anyone tell me what’s wrong here so I can learn to write my own migrations.
> > > 
> > > Roelof
> > > 
> > > –
> > > 
> > > You received this message because you are subscribed to the Google Groups “Ruby on Rails: Talk” group.
> > > 
> > > To post to this group, send email to [rubyonra...@googlegroups.com](mailto:rubyonra...@googlegroups.com).
> > > 
> > > To unsubscribe from this group, send email to [rubyonrails-ta...@googlegroups.com](mailto:rubyonrails-ta...@googlegroups.com).
> > > 
> > > To view this discussion on the web visit [https://groups.google.com/d/msg/rubyonrails-talk/-/\_J0oNDSxy9QJ](https://groups.google.com/d/msg/rubyonrails-talk/-/_J0oNDSxy9QJ).
> > > 
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

> >

> >

> Sorry I dont help me
> 
> I did rails g migration id\_category bericht And changed the migration file to this
> 
> class IdCategory \< ActiveRecord::Migration def up add\_column :bericht, id\_category, number end
> 
> def down end end
> 
> After that I did rake db:migrate and get this output :
> 
> == IdCategory: migrating ===================================================== – id\_category() rake aborted! An error has occurred, this and all later migrations canceled:
> 
> undefined local variable or method `id\_category’ for #IdCategory:0x00000004c3f0d8
> 
> Tasks: TOP =\> db:migrate (See full trace by running task with --trace)
> 
> Roelof

---

<div class="post-metadata">

**Author:** ![Norm2](https://avatars.discourse-cdn.com/v4/letter/n/3bc359/32.png) [@Norm2](https://discuss.rubyonrails.org/u/Norm2)\
**Post date:** [October 23, 2012, 3:10pm UTC](https://discuss.rubyonrails.org/t/whats-wrong-with-this-migration/65525/5 "2012-10-23T15:10:07Z")

</div>

You need something like

class IdCategory \< ActiveRecord::Migration &nbsp;&nbsp;&nbsp;def up &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;add\_column :bericht, 'id\_category', :integer &nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;def down &nbsp;&nbsp;&nbsp;end end

You can use either strings or symbols.

Norm

---

<div class="post-metadata">

**Author:** ![Roelof\_Wobben](https://avatars.discourse-cdn.com/v4/letter/r/e99b99/32.png) [@Roelof\_Wobben](https://discuss.rubyonrails.org/u/Roelof_Wobben)\
**Post date:** [October 23, 2012, 3:58pm UTC](https://discuss.rubyonrails.org/t/whats-wrong-with-this-migration/65525/6 "2012-10-23T15:58:00Z")

</div>

Thanks. Another problem solved.

Roelof
