Rails: ActiveRecord::PendingMigrationError - ruby-on-rails

I need some help getting my Cloud 9/Rails environment working again for an online course I'm working on through Upskill. I ran into a problem with one section and ended up rolling back to a previous commit. However, since I did that, I've run into some database errors I haven't been able to resolve.
Here is what I get when I try to access my app:
ActiveRecord::PendingMigrationError
Migrations are pending. To resolve this issue, run: bin/rails db:migrate RAILS_ENV=development
I've tried the suggested method to resolve it, but it hasn't worked, nor have a dozen other suggestions I've found in other threads with a similar message.
Below is what I see when I run rails db:migrate:status. So I believe maybe it has something to do with the third item there.
Status Migration ID Migration Name
up 20170331144924 Create contacts
up 20170406172755 Devise create users
down 20170410151911 Add devise to users
I am really lost but just hoping to get back to where I was so I can continue with the lessons. Thank you.

What worked for me was:
rake db:test:purge
rake db:test:prepare

Have you tried running a specific migration which is down like this? Ref
rake db:migrate:up VERSION=20170410151911

Related

IntelliJ Idea/Rubymine push to Heroku running db:migrate

I'm using IntelliJ Idea with the Rubymine plugin, and Heroku plugin, and I'm a bit stumped when it comes to pushing an app to Heroku. I can set it up and actually push the app: off it goes, and launches successfully. But even before I did that I was expecting it to fail because I couldn't find anyway of getting it to do a db:migrate. And so it proved: the app is launched but of course it fails pretty much immediately because there's no DB.
I've looked on the forums, google etc but nothing. Is this something that can only be done from the command line? I would have expected an IDE to be what it says on the tin: Integrated. So I feel I'm missing something. The Run configuration works as I've said, and the Heroku log has no errors, but I need a way to tell it to run the db:migrate before launching.
Any ideas?
The answer is that it is something that it doesn't do - confirmed by IntelliJ. So in this case, one needs to push the app to Heroku, drop to the command line and run the migration there: heroku run rake db:migrate.
I raised a feature request so this may be something that can be added in the future.
I haven't figured out how to do this automatically as part of the RubyMine/JetBrains Heroku Plugin. But you can cobble this together from other sources.
Start with this gist that creates rake tasks for Heroku operations provided by this answer to a similar question:
Then create a new run configurations for each Rake task that you will be using at some point. You will need at minimum push and migrate. But the other tasks might interest you.
Then create a new compound run configuration calling the Rake tasks you created in step 2 in the correct order.
Step 2 and 3 can be consolidated by creating one rake task for migration, and adding a before rake task to push. But that's kind of counter intuitive.
Note: that this approach does require you to have the Heroku CLI installed and configured with valid credentials.

heroku run rake db:migrate doesn't find app

I've tried everything - I always get Timeout waiting dyno or App not found.
can someone please help me use the right syntax or something - what in the world could I be doing wrong??
Here are some links that haven't helped:
https://twitter.com/viktorbenei/status/456913389928054784
heroku : run rake db:migrate error
https://devcenter.heroku.com/articles/one-off-dynos#timeout-awaiting-process
https://devcenter.heroku.com/articles/dynos
https://www.google.com/search?espv=2&q=how+to+deploy+rails+app+to+heroku+rake+db&oq=how+to+deploy+rails+app+to+heroku+rake+db&gs_l=serp.3...1923.3702.0.3978.8.8.0.0.0.0.258.775.0j4j1.5.0.msedr...0...1c.1.64.serp..5.3.520.88zR1b0gS6c
https://devcenter.heroku.com/articles/rake
Heroku run rake db:migrate results in no change in the database, app restarted several times
the problem was that I was trying to do this at work. I thought that it was communicating with the server because it would say things like app not found but it actually wasn't. when I tried this at home it worked fine.

Rails - Cant run any rake commands db is messed up

Everything was working fine yesterday and all of a sudden when i tried to run my server or run any rake tasks i get this error
Mysql2::Error: Table 'myapp_development.key_value_stores' doesn't exist: SHOW FULL FIELDS FROM `key_value_stores`
I've tried google searching and searching on stackoverflow all morning and cant find a solution to this
Try to rollback your migration file (take backup of the migration file will help while creating new ),
rake db:migrate:down VERSION=migrations's_version
and then try to restart the rails server.If you face same problem then with same migration number search in schema_migrations table in database delete that record and make new migration again.
I was struggling with this for a while but what i ended up doing
update xcode and update command line tools
uninstall then install mysql via homebrew
then i ended up manually removing my database folder in
usr/local/var/mysql/myapp
then i did a
rake:create
and then i just pulled my production database and copied it to my development database
rake db:backup_and_load
then I was up and running again
dont know which one of that fixed it specifically but thats what i did

ruby page on Heroku comes up with error: 'we're sorry but something went wrong'

Hi in the last week pushed a ROR rake task to prod and then ran the rake task to update some table fields in heroku.
Everything was seemed fine at the time but this week I did something that I hadn't done in the previous week of creating a new practice or editing one gives an error of 'we're sorry but something went wrong'
The error message I get from running --tail in the terminal says
Completed 500 internal server error in 34ms
ActionView::Template::Error (undefined method 'practices' for nil:NilClass);
This is my production application.
In the staging application I don't get this error.
The 2 environments are supposed to be the same.
Is a migration needed? or failing that how could I work out what is going wrong.
thanks
maggs
Run this command and try
heroku run rake db:migrate
Database
The 2 environments are supposed to be the same. Is a migration needed?
It depends on if you're using the same database in production & development
By default, Heroku gives you a blank PGSQL database, or you can override their DATABASE_URL config variable to use your own db:
heroku config:set DATABASE_URL=mysql://your_database
Recommendation
For now, I would recommend performing a heroku run rake db:migrate on your Heroku database, as this will provide the right data structure for your app
The real problem, though, is you're calling practices on an undefined object (nil:class). To ensure this is not a problem, you either need some logic such as:
unless #variable.nil?
# do something
end
or you need to ensure you're working with the correct data

rails test database errors with postgresql on OSX

So I have recently migrated to postgresql, and have been having issues with my test database creation. Whenever I run a rake task it seems to destroy my ability to access the test database that I have created. For example, if I run the following command
createdb -Ouser -Eutf8 example_test
I can run tests perfectly, however if I run a rake task I will get the following error:
.rvm/gems/ruby-1.9.2-p180#standard/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:991:in `initialize': FATAL: database "example_test" does not exist (PGError)
If I create a new test database like so:
createdb -Ouser -Eutf8 example2_test
Everything will work again, until I have to run a rake task. Does anyone know what this issue could be?
Fixed the bug, by finding the following blog post about the topic: http://katrinaowen.com/2011/01/05/using-postgresql-with-rails-3-cucumber-and-rspec
In short, this was a bug with creating databases with rspec installed, view the link and run the commands to get it to work on your system.
Perhaps you can look at log/development.log to see why the database is being dropped? And look at the rake task code itself to see what it is doing.
Usually the test database is generated via rake db:test:prepare based on config/database.yml

Resources