rake db:migrate does nothing, even on reset - ruby-on-rails

Here is a very strange issue I have on my new computer setup (otherwise, it's working on my other setups).
I'm running : rake db:migrate
No errors, but it does nothing...
rake db:migrate:status show me the list of pendings migrations (marked as "down"), the ones that I effectively have in my bd/migrate folder.
Even if I run those commands or removing files in db/* manually, db:migrate is still useless.
rake db:drop:all
rake db:create
rake db:migrate
I have tried also db:reset, db:rollback STEP=1000.
If I specify a VERSION number (one from the list given by db:migrate:status) as:
rake db:migrate VERSION=20150106184930
I've got the following error:
No migration with version number 20150106184930
I have also generated a new migration with:
rails generate migration TestMigration
And again, db:migrate completely ignor it.
My current setup is: windows7, rails 4.2.0, rake 10.3.2.
Thanks for any help, clues...

After hours of deep debugging in rake, reinstalled all my complete setup, I finally figured out that the problem was comming from the "non so special" characters [ or ] somewere in my project path!!
DAMN RAILS!
Due to readability, all my project's folders start with "[NAME-OF-PROJECT]xxxx/"... then in this particular rails project comes a subfolder for the rails app.
No error, nothing that point you out that the path name could be the issue. I'm quite sur that "[" and "]" are not forbidden character (even on linux) : http://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
And why "[" or "]" makes rake db:migrate failing and not rake db:migrate:status???
For me it clearly shows some weakness in rails architecture. I should probably do a bug report for that... can someone point me some report mailing list or whatever?
I hope that my misadventure will save hours for others.

If this is a new rails setup, you may not have gems on your system, but only in your app. Try prepending bundle exec to your rake commands.
bundle exec rake db:migrate

Try run gem update and try rake db:migrate again.

Related

Migrations are pending. To resolve this issue, run: bin/rake db:migrate RAILS_ENV=development error when running as server

I have tried to run as a server before and it worked well, I don't change anything in the database but when I tried to run again a have this message Migrations are pending. To resolve this issue, run: bin/rake db:migrate RAILS_ENV=development
i tried as this site link
but it failed
any help please
i am a beginner in ruby on rails
Migration files live in the db/migrate directory, and their names look like this:
20150121164407_create_comments.rb
From your comment, it looks like inside your db/migrate directory, you have several migrations with the same “basic” name create_comments (and probably different timestamps).
You need to remove one of those duplicated files.
If you did and if you don't have any important data in the database, you should destroy your database and recreate it using existing migrations. These commands in this order:
$ rake db:drop
if you're using postgres
$ rake db:create
and finally remigrate
$ rake db:migrate

Rails Project automatically deleted after rake db:reset

I was working on Nitrous.io on a Rails Project.
I have created a new branch and then after some coding , I reset the database with
rake db:reset.
After this action my Projects folders were automatically deleted.
Someone could help me understand what is wrong on my command?
db:reset will do exactly as described - it will "reset" the database. So db:reset is the same as executing the following commands: db:drop (which will drop/delete all entries in the database) + db:setup
I somehow doubt it that rake db:reset deletes your .rb files. Must be something else. Maybe you messed up with git?
rake db:reset
rake db:create
rake db:migrate
works just fine, normally.

Getting: "Migrations are pending; run 'bin/rake db:migrate RAILS_ENV=development' to resolve this issue." after cloning and migrating the project

I cloned my project. Bundled with "bundle install", then run "rake db:migrate". I am getting this error: (when I run the rails server and open my browser to localhost:3000) "Migrations are pending; run 'bin/rake db:migrate RAILS_ENV=development' to resolve this issue."
I checked all migrations one by one and all were executed without errors. Also no errors were shown after the execution of "rake db:migrate".
This is what I see when I execute "rake db:migrate:status"
I am on development environment. Please let me know if you need any other information.
I also tried "bundle exec rake db:migrate", and "bundle exec rake db:migrate:reset" as "burninggramma" suggested.
Any clues what causes the error?
Interesting. Did you run rake db:create? Assuming you are using sqlite3, do this:
rm -f db/*.sqlite3
rake db:create
RAILS_ENV=development bundle exec rake db:migrate
rails s -e development
Also, can you list the contents of your config/database.yml file?
Edit: Warning! Obviously, you will lose your existing data.
After running the migrate command, I still had the same error.
What worked for me was to just stop the rails server and start it again.
List your executed migrations with rake db:migrate:status and look if every migration was executed. You can try to cancel your migration with rake db:abort_if_pending_migrations and try to migrate again.
1. Maybe its default in ruby2/rails4 but have you tried: bundle exec rake db:migrate?
2. Another option would be resetting the whole database - use with CAUTION! resets all the data as well - bundle exec rake db:migrate:reset
+) I would just make sure that you are executing everything in the same development env:
RAILS_ENV=development bundle exec rake db:migrate:reset
RAILS_ENV=development bundle exec rails s
Running rake db:migrate RAILS_ENV=test did it for me
I had the same error in the browser, but upon closely looking at the error message, I noticed some how I had an extra white space in the migrate comment and post files. Once I removed it, it worked perfectly.
Open the database and click schema_migration table. The migrations will be listed as below.
Sort the version column and find the latest migration you want to go back. Delete or Insert a new one. Rails keeps all the migration history in this table, so you can adjust the migration history to you liking.
I got the same error working on the Learn Enough to Be Dangerous Rails tutorial. I'm using Git Bash terminals on a Windows 10 machine. The error showed up in the terminal where I'm running guard, after I tried to migrate my db using the command (in another terminal):
$ bundle exec rake db: migrate:
After trying the solution offered by #lewstherin, I still got the same error. I tried the command:
$ rails test
And got the explicit and helpful warning:
Migrations are pending. To resolve this issue, run:
bin/rails db:migrate RAILS_ENV=test
I ran the command:
$ bin/rails db:migrate RAILS_ENV=test
and now I'm working again.
For me i just had to migrate for the error:
rake db:migrate --trace
By setting false to config.active_record.migration_error in development.rb might make it workable but i wouldn't recommend it.
Here's what worked for me:
-gem install rails -v 4.1.0
Inside Gemfile:
-gem 'rails', '4.1.0'
(replace the newer/older with this)
Do bundle install and update
-bundle install
-bundle update
In your application.rb :
Remove/Comment - config.active_record.raise_in_transactional_callbacks = true
run bundle rake:
-bundle exec rake db:migrate
Refresh your page and the error should be gone.
Two reasons 'db:migrate:reset' did not work for me
1) loosing data
2) we moved from php to rails, so we had an existing DB and the migrations were written on top of it not from the scratch
So What I tried is to update the 'scheema_migrations'(mysql) table with the list of migrations(just version values) that I was really sure were already run on my db(development), this can be lil time consuming process but it works. I would not attempt this on production though.
I'm guessing the error is that you are creating a table that already exists, I had this problem before.
Step 1
look into the error when you rake dv:migrate
Step 2
go to the model where this table is created
Step 3
add drop_table :[YOUR TABLE] right before the create_table :[YOUR TABLE]
Step 2
run rake db:migrate
Step 3
remove the drop_table once the your migration is done
I had the same problem in genieacs and this code helped:
rake db:drop rake db:create rake db:schema:load RAILS_ENV=development
rake db:migrate rails s -e development
You can always run rake db:reset

Recreate database+tables (it dosn't want to work with rake commands) ROR 3

I'm newbie with ror and I just managed to ruin the databse... I tried to recreate with this 2 methodes bu none works:
first:
rake db:reset
rake db:migrate
second:
rake db:drop
rake db:create
rake db:migrate
But none work... I'm out of ideas what to do, please help...
My migrate folder is empty, if I migrate nothing happens, no table created notice.
Try using:
rake db:migrate:reset
examine your database.yml file, it might default to SQLITE which is basically a text file.
Make sure you are using the correct database with the correct name.

Rake error fixed by bundle exec, but deployment not working

I pushed an update to my Rails app production server, and in the update there was a new database migration. I ran rake db:migrate and got the common error seen here. I ran the rake again in bundle exec bash and it was successful. But after restarting my apache server, I'm now getting the 500 Error page. This update worked fine on my localhost, and was mostly this update to the db with supporting changes in the according view and controller/routing.
I don't even know why this error appeared this time, as I have pushed db updates successfully before using only rake. Nonetheless, the rake was successful. The 500 error page only shows on pages that require that specific new ActiveRecord. Any ideas on how to debug?
EDIT: My problem was an extremely simple one. I merely forgot to include the environment with the rake:
bundle exec rake db:migrate RAILS_ENV=production
Unfortunately, it took quite a while to narrow that down, as I couldn't use IRB to check the db entries until I followed these steps.
Did you run rake db:migrate on your server? Also be sure to set the RAILS_ENV flag so your production database is updated:
rake db:migrate RAILS_ENV=production

Resources