How to resolve Rails ActiveRecord::PendingMigrationError? - ruby-on-rails

When I try to load a page of my site, I get:
ActiveRecord::PendingMigrationError Migrations are pending.
To resolve this issue, run: bin/rake db:migrate RAILS_ENV=development
But when I when I run rake db:migrate I get:
SQLite3::SQLException table "options" already exists...
Running rake db:reset doesn't fix anything either. Trying to load a page still gives me the PendingMigrationError.
If instead I run rake db: drop and then rake db:migrate, I get this:
rake aborted
Standard Error! An error has occured, this and all later migrations canceled.
undefined method 'can_pick_many_options' ....
Note: I'm running Rails 4.1.2

Related

Rails Rspec - ActiveRecord::StatementInvalid: PG::InFailedSqlTransaction:

I have this controller method
def dashboard
method1
method2
method3
..
end
Everything is working fine in development environment..
but in test environment,
i am getting this error after first few methods.
I checked using binding.pry just above the line which i used to get error,
I cannot run any query eg: Account.first
but same Account.first works in dev environment
Error when i run in test environment:
ActiveRecord::StatementInvalid: PG::InFailedSqlTransaction: ERROR: current transaction is aborted, commands ignored until end of transaction block
: SELECT "accounts".* FROM "accounts" ORDER BY "accounts"."id" ASC LIMIT 1
from /home/qwinix/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/postgresql_adapter.rb:596:in `async_exec'
Please note the following
No erros found in other controllers and respective spec.
There was no error in the same controller from other branch
I added few code to method1, which executes just fine in both environment. i am getting these error after method3 which i havent touched.
PS: I did google and search stackoverflow questions, didnt help
Edit: When i moved the method1 to end, i am not getting any errors, please explain me this behaviour.
Did you try to reset the Test Database?
bundle exec rails db:drop RAILS_ENV=test
bundle exec rails db:create RAILS_ENV=test
bundle exec rails db:schema:load RAILS_ENV=test
or for Rails Version older than 5
bundle exec rake db:drop RAILS_ENV=test
bundle exec rake db:create RAILS_ENV=test
bundle exec rake db:schema:load RAILS_ENV=test
or shorter:
bundle exec rake db:reset RAILS_ENV=test

rake db:migrate giving exception, rake aborted

I cloned a repo from bitbucket now trying to set it up on localhost machine.
SQLite3::SQLException: no such table: test_123: ALTER TABLE "test_123" ADD "icon_file_name"
rake db:drop
rake db:create
rake db:migrate
But still getting that same issue. What is solution for this?

why does rake db:migrate say my development database doesn't exist?

I'm typing in the terminal
rake db:migrate
Here's the error Im getting
ActiveRecord::NoDatabaseError: FATAL: database "db/development.sqlite3" does not exist
rake db:migrate doesn't create database, rather requires it exists.
rake db:create creates a database without loading database schema.
Remember you should run rake db:create before you can run rake db:migrate if you dropped database with rake db:drop.

Pending migrations error when running rake db:migrate

I getting this weird error from Rails:
$ rake db:migrate
You have 1 pending migrations:
20150226203752 CreatePlan
Run `rake db:migrate` to update your database then try again.
But that's exactly what I'm trying to do!
Anyone knows why I'm getting this?
Things seem to have gone wrong somewhere, run all your migrations again using rake db:migrate:reset

Migrations are pending; run 'bin/rake db:migrate RAILS_ENV=development' to resolve this issue [unable to proceed]

I appear to have a circular issue in regards to Ruby on Rails migration procedure. I am following the introduction article and I have reached the point when I need to create my first table.
I have ran the following,
[tims#web2 working_ror]# rails generate model Homepage first_name:string last_name:string email:string message:text
invoke active_record
create db/migrate/20131119203948_create_homepages.rb
create app/models/homepage.rb
invoke test_unit
createtest /models/homepage_test.rb
createtest /fixtures/homepages.yml
I then proceeded with the migration,
[tims#web2 working_ror]# rake db:migrate
== CreateHomepages: migrating ================================================
-- create_table(:homepages)
-> 0.0493s
== CreateHomepages: migrated (0.0494s) =======================================
, however, when I run my application I see the following message,
Migrations are pending; run 'bin/rake db:migrate RAILS_ENV=development' to resolve this issue.
but, IF I run the above,
[tims#web2 working_ror]# rake db:migrate RAILS_ENV=development
[tims#web2 working_ror]#
and the message continues ...
I have spent considerable amount of time researching forums in-which the closest I could find was to drop and re-build everything, which have done the following.
rake db:drop
rake db:create
rake db:migrate
and the results are the same.
You need to do
bundle exec rake test:prepare
or
bundle exec rake db:test:prepare
and then
bundle exec rake db:migrate
before running the specs
Cheers
cited from : Why am I asked to run 'rake db:migrate RAILS_ENV=test'?
you can do
bundle exec rake test:prepare
In Rails 4.1+, they deprecated db:test:prepare
You can now just use:
ActiveRecord::Migration.maintain_test_schema!
If you need to do it manually
rake db:schema:load RAILS_ENV=test
and then
bundle exec rake db:migrate
try
In RAILS_ROOT/config/environments/development.rb Set the following setting to false:
config.active_record.migration_error = false#:page_load
One weird trick that you can use when your migrations are screwed (file deleted, manually renamed, etc.)
Fire up your favourite DB admin tool (eg. PGAdmin3) and browse to the database in question.
Look for a table called schema_migrations and browse its content. It should have a single column called version. This field is used by Rails to check whether migrations are up to date.
Make sure that your migration timestamps corresponds with the data in this column. If you have deleted an older migration, delete the corresponding timestamp.
Check to make sure that table doesn't already exist:
type - rails dbconsole
type - .tables (check to see if there was an error during the rake db:migrate that has the table name like -- create_table(:test) rake aborted!)
If you see the table name after running the .tables in the console type - drop table TABLENAME;
Then .quit to go back to the branch and run the rake db:migrate command again.
this was what i did:
rails db:environment:set RAILS_ENV=test
If you need to do it manually
rake db:schema:load RAILS_ENV=test
and then
bundle exec rake db:migrate
Thanks to Ahmed Ali....... your comment was helpful.

Resources