the VERSION value at in rake db:migrate VERSION=[versionNumber] is the
migration number right? for instance lets say I have 3 models
generated in this respective order albums, users, and reviews. If I
do “rake db:migrate VERSION=0”, it will delete the data and existence
of all three tables…if I do VERSION=1, it will delete the existance/
data of users and reviews etc etc…
So my problem is I rolled back to VERSION=0, added a column to Review
in the migration file, and migrated again. For some reason rails
didn’t acknowledge the change and the table indecies are still the
same.
So my before I rolled back to version 0:
class CreateReviews < ActiveRecord::Migration
def self.up
create_table :reviews, :force => true do |t|
t.text :productReview
t.string :product
t.string :productCreator
t.timestamps
end
end
def self.down
drop_table :reviews
end
end
I then put in a coloumn called album_id
class CreateReviews < ActiveRecord::Migration
def self.up
create_table :reviews, :force => true do |t|
t.text :productReview
t.string :product
t.string :productCreator
t.integer :album_id
t.timestamps
end
end
def self.down
drop_table :reviews
end
end
Rand db:migrate and checked my structure in the console and it’s still
the previous version without album_id…
same.
t.timestamps
I then put in a coloumn called album_id
Any thoughts?
The general idea is that when you want to change a model (i.e., add a
column), that you created a new migration that adds the column to the
table rather than migrate down and lose data.
If however, you rake db:migrate VERSION=0, can you confirm indeed that
the ‘reviews’ table is indeed dropped?
Yeah that sounds more feasible rather than migrating down…I can
definitely
confirm VERSION=0 will drop the table though because when try to load
the
structure in the console it throws me an error.
What would be the syntax to just add a change(thus adding a new
migration
then)
I want to add t.intger :album_id. I’m assuming it’s a command at the
command line that will product and 004 migration file?
I was able to generate the file w/the command and I added the
“add_column”
code. When I do my migrate I can see rail iteratively compiling the
files
and I see the
It worked. Thank you…please excuse me while I go shoot myself for
not
trying that already. It’s funny restarting the console has worked in
some
instances like this before…but I was lazy and did “reload!” instead.
Rails is funny…
Thanks again
Jon
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.