I added the gemfile:
gem 'activerecord-reputation-system', require: 'reputation_system'
to my Rails app in order to add upvote/downvote functionity to a model (I'm following Railscast #364). I installed the gem with no problems.
I entered 'rails g reputation_system' and rake db:migrate, but the rake was aborted:
Gem::LoadError: You have already activated rake 12.3.0, but your
Gemfile requires rake 12.0.0. Prepending `bundle exec` to your command
may solve this.
I tried it with 'bundle exec', but the rake was aborted again:
StandardError: An error has occurred, this and all later migrations
canceled:
Directly inheriting from ActiveRecord::Migration is not supported.
Please specify the Rails release the migration was written for:
I updated my gems to see if this was the trouble, but this made no difference.
I can't think of anything else I could do other than finding some way of removing rake 12.3.0 and installing 12.0.0, but this seems illogical.
Any help would be much appreciated, thanks :-)
In Rails 5 migrations require you to specify the Rails version you’re using (the migration is specified for) at the top of your migration file, as the error states.
This looks like this:
class CreateYourModels < ActiveRecord::Migration[5.1]
...your migration code
end
Where the bit in brackets is the Rails version you're using.
Then try to run bundle exec rake db:migrate.
Additional explanation: https://blog.bigbinary.com/2016/03/01/migrations-are-versioned-in-rails-5.html
Related
I've been running a Rails 3.2 with Ruby 1.9.3 for a while now. Recently I added Rails 5.1 and Ruby 2.4.
I used rvm to install Ruby2.4.
Today I had occasion to cd into one of my old projects and run rake db:migrate, and I got the following message:
Gem::LoadError: You have already activated rake 12.0.0, but your Gemfile requires rake 0.9.2.2. Prepending `bundle exec` to your command may solve this.
Prepending 'bundle exec' did solve the problem but for my knowledge I would like to understand what happened. I thought the whole point of a Gem file within the project was to lock in the required gems.
So somewhere on my machine clearly there is still rake 0.9.2.2 but why did my command 'rake db:migrate' not use that automatically?
Reason: Some of the gem might have locked rake gem to that version.You are getting this as version of rake inside gemlock file is different than the one you have already installed.
Solution1:
bundle update
Solution2:
edit the gemlock file. open Gemfile.lock and change
rake (0.9.2.2) to rake (12.0.0)
Solution3:
remove Gemfile.lock and run bundle install once again.This will create
Gemfile.lock once again.
When I do rake db:migrate, I get the following error:
rake aborted!
Gem::LoadError: You have already activated rake 10.2.2, but your Gemfile requires rake 10.1.0. Using bundle exec may solve this.
How can solve this?
This error is due to the fact that some applications may specify different versions of gems than the ones you have installed.
Try using bundle exec rake db:migrate.
Using bundle exec guarantees that the program is run with the environment specified in the gemfile.
Perhaps:
bundle exec rake db:migrate
There might be other gems in the Gemfile which are dependent on rake 10.2.2, while you are trying to install rake 10.1.0 via your gemfile or explicitly mentioned it. A look into your Gemfile will help.
In case you have specific environment, you may want to run
bundle exec rake db:migrate
to make sure you are running it appropriately.
As per another answer given on this topic, you can also try deleting the Gemfile.lock file and re-running bundle install to regenerate the Gem dependencies.
I am using 'rake 0.8.7' in my Rails project and yet when I still try either rake routes or bundle exec rake routes I still get
rake aborted!
uninitialized constant Rake::DSL
If I try putting the recommended require 'rake/dsl_definition' in my Rakefile it gives me
rake aborted!
no such file to load -- rake/dsl_definition
So, I'm stuck at how to fix this. I can't run any rake commands...
That error sounds like you are using something in your app that requires a more recent version of rake than 0.8.7. Believe Rake::DSL only showed up in rake 0.9.0.
The most recent version of Rails advertises itself as working with rake as old as 0.8.7. Perhaps it's wrong. More likely you're using some other gem in your project which requires a more recent rake.
Why and how are you using rake 0.8.7 in your project instead of a more recent one? Unless you've locked to rake 0.8.7 in your gemfile (or are using some other gem that insists on 0.8.7), you should be able to run bundle update rake to upgrade to the most recent version of rake.
If you have multiple versions of rake installed, you may have to run bundle exec rake ..., as you noted. But in your project, bundle exec rake still gets you 0.8.7, because for whatever reason that's the version of rake your Gemfile.lock is currently set to -- but your project is using something that wants a more recent version.
I just updated refinerycms-news engine in my Gemfile from '~> 0.9.8' to :git => 'https://github.com/resolve/refinerycms-news.git', and now there is an error caused by a missing column. The migration to create the column can be found in the installed gem, but rake db:migrate does nothing. Is there another rake task or other step that will run it?
You'll have to follow this convention for Refinery CMS:
rails generate refinerycms_news
rake db:migrate
The generator copies only new migrations in and then rake db:migrate runs them.
Cheers,
Phil
I am trying to install and run Spree on my local machine by following the steps mentioned in Getting started with Spree
However, when I start the server I get the following error:
Could not find table 'pages'
Can someone please help me out with this?
Solved the issue!
Generated the following generators:
spree_static_content and spree_product_assembly which did the magic!
Could not find table 'pages' means rails is not being able to find that table in the database.
In those instructions, review the section 'configuring the database' and then '4.6 Populating the Database'.
It sounds like you want to give spree a go, but don't have experience with Rails.
The spot where you are stuck is not something specific to spree, its a step required in setting up all rails projects referred to as database migration.
For what you need to know about migrations the official Rails Guides are great.
http://guides.rubyonrails.org/migrations.html
For a comprehensive intro to Rails which may also answer a few of your other questions, check out http://railstutorial.org/ruby-on-rails-tutorial-book
If you just want to try stuff.. the spree tute is on track
Do these steps again..
(If it generates an error, to a rake db:drop first to get rid of what you have already done)
rake db:create
rails g spree:site
rake spree:install
rake spree_sample:install
rake db:bootstrap
rake db:migrate
rake db:seed
rake db:sample
rake db:admin:create
Here is what I did to get Spree up and running:
Create a new rails project:
$ rails new spree_project
Add these 5 gems to the projects Gemfile (/spree_project/Gemfile):
gem 'spree', :git => 'git://github.com/spree/spree.git'
gem 'spree_auth_devise', :git => 'git://github.com/spree/spree_auth_devise'
gem 'spree_gateway', :git => 'git://github.com/spree/spree_gateway.git'
gem 'spree_usa_epay'
gem 'spree_skrill'
Run a bundle install and setup the database (rake db:bootstrap did not work for me)
$ bundle install
$ rake db:migrate
$ rake db:seed
$ bundle exec rake spree_sample:load
The 'pages' table is used by the spree_static_content gem. You can either remove the gem from your gemfile, or you can generate migrations for the static content gem:
rails generate spree_static_content:install
If you've included the 'spree_product_assembly' gem as well, you'll want to do the same for it:
rails generate spree_product_assembly:install
Then, reset the database (just to make sure)
rake db:bootstrap
rake db:admin:create
I ran into similar issues after trying the http://spreecommerce.com/documentation/getting_started.html instructions, but it seems to have created a nice demo app after taking these additional steps.