Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with Rails 3 and MySQL related to JSON dependency in ActiveSupport

I built my Rails 3 app using sqlite and now I'm trying to switch over to MySQL.

I created a new MySQL db, changed database.yml accordingly, and I added an older version of the mysql2 gem to my gemfile (gem 'mysql2', '< 0.3') which is supposed to play nicer with Rails 3.

I can start the dev server fine. When I visit a page, I get a Mysql2::Error (Table 'twitter_quiz_development.users' doesn't exist). Which is fine--I still need to add the schema to the new db. This is where I run into trouble:

rake db:schema:load returns this nasty error.

The solution found here did not work for me. gem pristine --all return this.

I'm running Ubuntu 11 if that helps.

It appears that the error has to do with JSON but I have no idea how to solve this. Thanks.

like image 705
user94154 Avatar asked Jun 03 '11 00:06

user94154


2 Answers

The issue(s) you are experiencing could be due to 3 things:

  • The version of Ruby you are using
  • The use of the SystemTimer gem with Ruby 1.9
  • The JSON gem

I've elaborated below...

The first thing I would suggest is to upgrade your version of Ruby 1.9. The latest stable is:

ruby 1.9.2p180 (2011-02-18 revision 30909)

I would highly recommend using Ruby Version Manager (RVM) to install and manage Rubies.

In terms of using the JSON gem, have a look at: http://ruby.about.com/od/tasks/a/The-Json-Gem.htm

To quote:

On Ruby 1.8.7, you'll need to install a gem. However, in Ruby 1.9.2, the json gem is bundled with the core Ruby distribution. So, if you're using 1.9.2, you're probably all set. If you're on 1.8.7, you'll need to install a gem.

Before you install the JSON gem, first realize that this gem is distrubuted in two variants. Simply installing this gem with gem install json will install the C extension variant. This requires a C compiler to install, and may not be available or appropriate on all systems. Though if you can install this version, you should.

If you can't install the C extension version, you should gem install json_pure instead. This is the same gem implemented in pure Ruby. It should run everywhere that Ruby code runs, on all platforms and on a variety of interpreters. However, it's considerably slower than the C extension version.

Edit:

Looks like you should avoid using the SystemTimer gem with Ruby 1.9. See this for more info: http://isitruby19.com/systemtimer

To quote a comment made on that page by Phillipe:

I am the (co)-author of this gem. Short story : Using this gem in Ruby 1.9 is useless and does not make any sense!

System Timer is trying to work around some limitation of the "green thread" model used in Ruby 1.8 (MRI). See http://ph7spot.com/musings/system-timer for more details.

It is then irrelevant in a Ruby 1.9 which abandoned the green thread model and embraced native threads (kind of since there is still a global interpreter lock).

Cheers, - Philippe

like image 57
Jits Avatar answered Nov 16 '22 04:11

Jits


Your gem pristine --all looks like it errored out with the SystemTimer gem before it got to the json gem. Is that gem used in the Rails app in question?

Are you using RVM? If so, I'd manually remove the SystemTimer and json gems and their binaries (if any) from ~/.rvm/gems/ruby-whatever-version/ (in the gem and bin subdirectories).

Try to update to the latest version of the JSON gem (1.5.1) by adding this to your Gemfile:

gem "json", "1.5.1"

And then run bundle install to install SystemTimer and the later version of the json gem.

like image 1
nfm Avatar answered Nov 16 '22 02:11

nfm