I’ve decided to jump into Migrations before I get too far along on the
DB side of things.
I already have some tables built, and I went ahead and built the
migration that would have created them from scratch, and I made sure
that there was a self.down section to drop them. I wanted to verify
that I could roll back so I figured I would use rake to drop these
pre-existing tables before I recreated them.
Sure enough, if I run rake migrate, I get the error that says the tables
already exist. Great - that means rake can find my migration and the
“up” section is probably valid.
However, if I do
rake migrate VERSION=0
which I am understanding should undo the first migration, nothing
happens.
Sure enough, if I run rake migrate, I get the error that says the tables
already exist. Great - that means rake can find my migration and the
“up” section is probably valid.
Your problem is probably that the tables already do exist. This makes
Migrate error out before completing. If it were successful, it would
set the version for the migration in the database. This probably has
not been set (or is 0) so the Migrate Version=0 thinks it is already
in that state.
Two options. Delete the tables, then run the initial Migration so
it’s populated fully. Jump into the db itself and set the version
value to 1 manually in the migrations table (sorry I should know the
table name offhand, but don’t…it’s obvious though).
Sure enough, if I run rake migrate, I get the error that says the tables
already exist. Great - that means rake can find my migration and the
“up” section is probably valid.
Your problem is probably that the tables already do exist. This makes
Migrate error out before completing. If it were successful, it would
set the version for the migration in the database. This probably has
not been set (or is 0) so the Migrate Version=0 thinks it is already
in that state.
Two options. Delete the tables, then run the initial Migration so
it’s populated fully. Jump into the db itself and set the version
value to 1 manually in the migrations table (sorry I should know the
table name offhand, but don’t…it’s obvious though).
-Curtis
Curtis,
That makes sense.
Thanks,
Wes
Yep, that was it. I modified the schema_info table to set the current
version to 1 and then was able to revert.
I’m happy - looks like Migrations works well so I’m glad to be able to
integrate it into my experience and move on :).
Sure enough, if I run rake migrate, I get the error that says the tables
already exist. Great - that means rake can find my migration and the
“up” section is probably valid.
Your problem is probably that the tables already do exist. This makes
Migrate error out before completing. If it were successful, it would
set the version for the migration in the database. This probably has
not been set (or is 0) so the Migrate Version=0 thinks it is already
in that state.
Two options. Delete the tables, then run the initial Migration so
it’s populated fully. Jump into the db itself and set the version
value to 1 manually in the migrations table (sorry I should know the
table name offhand, but don’t…it’s obvious though).
** Invoke environment
end
Does rake migrate VERSION=0 rollback the very FIRST migration?
What am I doing wrong?
I can’t answer the question but I never bothered to try because the
first schema dump I did, I copied into the first migration file and I
was done. That was certainly capable of creating the ‘testing’ db and
the ‘production’ db’s so I know it worked so going back to ‘0’ never
seemed to be an issue
Craig
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.