whats wrong with this migration

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 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…

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

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.

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.

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

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

Thanks. Another problem solved.

Roelof