aris
1
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
roelof
2
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
3
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 V. het
volgende:
roelof
4
Op dinsdag 23 oktober 2012 17:03:29 UTC+2 schreef roelof het volgende:
roelof
5
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
roelof
6
Thanks. Another problem solved.
Roelof
Op dinsdag 23 oktober 2012 17:10:51 UTC+2 schreef Norm het volgende: