rake db:seed with Rails/Spree on AppFog - ruby-on-rails

I'm testing a Rails/Spree app on appfog, but I can't get the DB to seed.
I've followed these instructions to the T:
https://docs.appfog.com/languages/ruby/rails
But at the point where I run af tunnel and then open a new terminal window, then run RAILS_ENV=proxied-appfog rake db:seed I get the error
loading fixture /var/lib/gems/1.9.1/gems/spree_core-1.3.2/db/default/spree/countries.yml
rake aborted!
Mysql2::Error: closed MySQL connection: SET FOREIGN_KEY_CHECKS = 1
I'm using MySQL for the db.
Any thoughts on why this is happening?
rake:db migrate runs with no errors.
rake:db reset fails with the same error.

Maybe you run af tunnel, but it is incomplete. You have to run some like af tunnel my-app-mysql-1234 and then select 1 option (none)
Check my recent answer and change the RAILS_ENV=production rake db:migrate per some like RAILS_ENV=production rake db:seed
App Fog Rails Migrate Database
Its work fine for me.
Good luck!

Related

Error when running bin/rails test in Vagrant

I'm running the rails-dev-box on Vagrant, with a folder shared between the box and my Windows computer. Rails version 5.0.5. I have a very basic app using a sqlite3 database, and a basic generated scaffold for a model. When I ran bin/rails test I received this error:
ActiveRecord::Tasks::DatabaseAlreadyExists
A link in this GitHub thread pointed to this SO question, and I followed this answer - I edited database.yml to change the location of the databases to a location outside of the shared folder. I then re-migrated the databases with bin/rails db:migrate. This seemed to help a bit, because the next time I ran bin/rails test I received a different error:
Migrations are pending. To resolve this issue, run:
bin/rails db:migrate RAILS_ENV=test
But even after running bin/rails db:migrate RAILS_ENV=test I still receive this error each time I try to run the test.
I think all you need is bin/rails db:test:prepare before bin/rails test

Rails - FATAL: database "myapp_development" does not exist

I am trying to set up my Env to use PostgreSQL with Rails and i followed the steps to install PostgreSQL from this Article
Am getting the following error
ATAL: database "myapp_development" does not exist Extracted source
(around line #661):
rescue ::PG::Error => error
if error.message.include?("does not exist")
raise ActiveRecord::NoDatabaseError.new(error.message, error)
else
raise
end
Did you run rake db:create and rake db:migrate before rails server?
UPDATE
Here's all the steps you should do:
cd /your/app/path
bundle install
bundle exec rake db:create
bundle exec rake db:migrate
bundle exec rails server
Run
rails db:create
before running
rails db:migrate
You can also create PostgreSQL database manually by using psql command prompt.
When in there, connect to your local server and write "create database myapp_development;" without the quotes
I was having a similar problem. I checked different websites and tried what they suggested but didn't work. Then I tried rake db:create:all and rake db:migrate it worked for me. Thank you!
You can fix it by:
bundle exec rake db:setup
In my case, the solution was to provide what the error said.."create the database that does not exist"....I spent many hours trying different commands or run db:migrate using bundle but none of that worked. I thought it should create the db on it's own but no...I eventually decided to create the db in postgres
sudo su - postgres
psql
CREATE DATABASE tableNameFromDatabase.yml WITH OWNER myusername;
after this rails db:migrate worked

Rails shows all migrations as pending

I have a Ruby on Rails application that is successfully running on Heroku.
I did some experimentation with RSpec and Cucumber, but at some point running the server locally failed with the message
Migrations are pending. To resolve this issue, run: bin/rake
db:migrate RAILS_ENV=development
I ran rake db:migrate:status and literally all 50 or so of my migrations are marked as "down", even ones created months ago:
When I try to run the command it gives me, it gives me
PG::DuplicateTable: ERROR: relation "artists" already exists
which is fair enough since it does, it's an old migration. So the problem is that it's not detecting that these migrations were already run.
Here's what I've tried:
A git reset to the last working state (my heroku instance)
Restarting Postgres, the rails server and my Mac
Running rake db:reset, as well as rake db:drop db:create db:migrate
None of which worked. I'm desperate to get my app back into a state where I can continue development on it.

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

Rake Migrate will not work on developement

I'm following along with some tutorials and they are teaching how to create and run migrations. All has been working so far but I have run in to a problem. But now when i have come back to it the migration will not work in the development database. I used rake db:migrate RAILS_ENV=production to see if my migrations work and on that database it can go through all the migrations and back down again with no problems are errors but when I run rake db:migrate RAILS_ENV=development it pauses for a few seconds then returns me to the console awaiting a command. No errors are shown or nothing is returned to show what it has done and when checking the DB nothing has changed. What can this be?
Use --trace
rake db:migrate --trace
Show your database.yml file please.

Resources