Reputation: 2240
Here is the basics. I had a deployment on a SANDBOX environment.
I made some changes, and attempted to redeploy. The Stack is Cap3 with a Postgres DB / Rails 4.2
Upon deployment, which has never had any issues prior, when it came to run the migrations, which it shouldn't have because there were no pending ones, it basically rolled back all of the migrations to a 0 state.
I successfully created this error in the development environment. I had to recover the schema file from a previous commit, because the reversion of course rolled everything back.
so right now.
ActiveRecord::Schema.define(version: 20151214201502) do ...
And the last migration file is
20151214201502_create_host_group_membership_table
When I try and deploy, or run rake db:migrate
I get a total reversion. All tables get dropped.
Schema.rb reads ActiveRecord::Schema.define(version: 0) do
and the rake db:migrate:status
reads >
Status Migration ID Migration Name
--------------------------------------------------
down 20150916151324 Create ...<edited> table
down 20150916190627 Create ...<edited> table
down 20150916195012 Create ...<edited> table
down 20150918112956 Create ...<edited> table
down 20151019175551 Create ...<edited> table
down 20151020195644 Create ...<edited> table
down 20151020202321 Create ...<edited> table
down 20151026021111 Create ...<edited> table
down 20151124161525 Create ...<edited> table
down 20151124185807 Create ...<edited> table
down 20151214201502 Create ...<edited> table
and any subsequent rake db:migrate results in nothing.
Upvotes: 3
Views: 595
Reputation: 955
I had exactly the same issue, but Eric's answer didn't work in my case.
What did the trick was to drop the db, erase the schema and create and migrate the db:
$ rails db:drop
$ rm db/schema.rb
$ rails db:create
$ rails db:migrate
Upvotes: 0
Reputation: 1765
If you overwrite the ENV["VERSION"], the rake db:migrate
will go downgrade rather than upgrade if VERSION is smaller than last known VERSION in db schema, so please check and avoid similar environment variable.
Upvotes: 1