whats wrong with this migration

12 views
Skip to first unread message

roelof

unread,
Oct 23, 2012, 10:49:44 AM10/23/12
to rubyonra...@googlegroups.com
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

BalaRaju Vankala

unread,
Oct 23, 2012, 10:56:14 AM10/23/12
to rubyonra...@googlegroups.com
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..


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.
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/_J0oNDSxy9QJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 






roelof

unread,
Oct 23, 2012, 11:03:29 AM10/23/12
to rubyonra...@googlegroups.com
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



Op dinsdag 23 oktober 2012 16:56:42 UTC+2 schreef BalaRaju Vankala het volgende:

roelof

unread,
Oct 23, 2012, 11:04:25 AM10/23/12
to rubyonra...@googlegroups.com


Op dinsdag 23 oktober 2012 17:03:29 UTC+2 schreef roelof het volgende:

Norm Scherer

unread,
Oct 23, 2012, 11:10:07 AM10/23/12
to rubyonra...@googlegroups.com
You need something like


class IdCategory < ActiveRecord::Migration
  def up
    add_column :bericht, 'id_category', :integer

  end

  def down
  end
end

You can use either strings or symbols.

Norm
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/Y-uT61sr6GoJ.

roelof

unread,
Oct 23, 2012, 11:58:00 AM10/23/12
to rubyonra...@googlegroups.com
Thanks. Another problem solved.

Roelof

Op dinsdag 23 oktober 2012 17:10:51 UTC+2 schreef Norm het volgende:
Reply all
Reply to author
Forward
0 new messages