2

I have a strange problem with rails migrations. My db/migrate folder contains migration files and all worked fine. But a few moment ago, I created a new file using rails g migration MigrationName, it generated a new file. then when i had runned rake db:migrate it rollbacks all and my schema version became 0. Now when i run rake db:migrate it does nothing whereas db/migrate contains all my migrations. i tried rake db:reset db:drop db:create db:migrate but no migrations was performed. However it says "migrations are pending run rake db:migrate RAILS_ENV=development" what i've done in vain.

I'm confused. Is anyone ever had this problem?

i've just tried RAILS_ENV=development rake db:migrate --trace and it returns:

** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
** Invoke db:_dump (first_time)
** Execute db:_dump
** Invoke db:schema:dump (first_time)
** Invoke environment 
** Invoke db:load_config 
** Execute db:schema:dump

Running:

rake db:migrate:status 

gives me:

database: database_development 
Status Migration ID Migration Name
--------------------------------------------------
up 000 ********** NO FILE ********** 
down 20150613120151 Devise create users 
down 20150613120734 Devise create admins 
down 20150614114949 Create gender 
down 20150614115642 Create events 
down 20150614142610 Create multi events

I tried so many things: - i dropped my database, restarted postgresql and run again rake db:setup db:migrate. rake db:migrate:status tells me that migrations are pending but it wont migrate. it makes me crazy...

EDIT I manually updated schema_migrations in database adding the timestamps schema:load worked, but when i run rake db:migrate to check if its all good, it rolledback..

EDIT if i manually fill schema_migrations version in database with timestamps, when i do rake db:schema:status they are all to up and my new migration to down, but if i do rake db:migrate it tries to revert as if i wanted to run rake db:rollback

3
  • hello, thanks for helping. I don't know what is this 000 migration. I don't understand too. I tried to migrate with production environment on my local machine it works. Commented Jun 14, 2015 at 15:19
  • i'll try this. But this 000 migration comes everytime i run rake db:create Commented Jun 14, 2015 at 15:22
  • Ok it seems normal that Rails generates this 000 file then you run db:create. Commented Jun 14, 2015 at 15:33

2 Answers 2

2

So i fixed my issue. In fact, i'm using dotenv to manage environment vars for development, and in my .env file i defined a var called VERSION to describe the API version... That is the bug ! When i removed it, rake was able to migrate as expected.

Sign up to request clarification or add additional context in comments.

2 Comments

I had this same problem! Thanks for saving me some time.
I had the same issue and fixed by unset VERSION the same as you. How ever, It's not a bug. The db:migrate use var VERSION to migrate the specific version. So in our case, it intends to run the specific version set in the ENV variable.
0

I am not sure this will work for, but can you please try the following things,

First, drop tables

rake db:drop

Second, Delete/Remove db/schema.rb file

Third, create database

rake db:create

Fourth, run migration again

rake db:migrate

Please let me know if this help you a bit, good luck :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.