no such file to load -- sqlite3 WITH mysql2

There are many threads showing the error...

     no such file to load -- sqlite3

BUT they are all reported by people using sqlite3 wherease I am using mysql2.

My gemfile clearly says mysql2. My database.yml file definitely only has mysql2 configuration in it. And a search of my project shows no files containing any reference to sqlite3.

So why am I getting this message and how to I fix it?

I can run db:create ok (and the mysql TEST and DEVELOPMENT databases are created) but when I run db:migrate then I get this error.

It might be worth posting the complete output from the rake command with --trace specified.

Also which Rails are you using? Which OS? Is this a new install and this is your first app? Output from gem list.

Colin

Colin Law wrote in post #963675:

It might be worth posting the complete output from the rake command with --trace specified.

Also which Rails are you using? Which OS? Is this a new install and this is your first app? Output from gem list.

Colin

Hmmm. I forgot a lot of clues there didn't I. Sorry about that...

It's one of several Rails projects and the others do not have this problem. I'm building the DEPOT application from the Agile book and wanted to see if their version v (depot_v) code would resolve another problem I'm having...

The "other problem" is that TEST FUNCTIONALS seems to set up the TEST DB and then quickly erase it just before running the FUNCTIONALS test which then fails because the tables are not found. Everything else apart from this is working fine.

I'm running under Windows 7, Rails 3.0.3. Ruby 1.9.2.

I'm in the midst of wiping the DEPOT version "v" and setting it up again. Version "g" for example doesn't have this problem.

Will report back in 10 mins or so on whether setting it all up again worked or changed anything.

Thanks for your reply to my question.

Steve Mills wrote in post #963677:

I'm in the midst of wiping the DEPOT version "v" and setting it up again. Version "g" for example doesn't have this problem.

Will report back in 10 mins or so on whether setting it all up again worked or changed anything.

That didn't make any difference.

Looking at the earlier version which seemed ok, and this version that is not, the main difference is the following in the GEMFILE...

gem 'activemerchant', '~> 1.9.0' gem 'haml', '~> 3.0.18' gem 'jquery-rails', '~> 0.2.2'

Could it be that although my application is using mysql2 that one of these things assumes or requires sqlite3?

Kind Regards Steve

I would not have thought that likely, though I know nothing about activemerchant. Does rake --trace give any indication of where sqlite might be included?

Colin

post your Gemfile and database.yml in pastie.org

Best Regards, Luciano Sousa http://www.lucianosousa.net

http://twitter.com/lucianosousa http://rubyonrio.org *Ruby on Rails Developer *Linux User #456387

*Contact: +55 21 8418-5945

Luciano Sousa wrote in post #963685:

post your Gemfile and database.yml in pastie.org

Done <script src='http://pastie.org/1325155.js’></script>

Hope I did it right? I've not used pastie.org before.

Kind Regards Steve

I think that should just be http://pastie.org/1325155

Colin

its ok! the config not have problem… ;s

post your rake db:migrate --trace… :wink:

Best Regards, Luciano Sousa http://www.lucianosousa.net

http://twitter.com/lucianosousa http://rubyonrio.org *Ruby on Rails Developer *Linux User #456387

*Contact: +55 21 8418-5945

Luciano Sousa wrote in post #963876:

post your rake db:migrate --trace...

Done. http://pastie.org/1325873

Kind Regards Steve

OK. I now know why this is happening but I don't know what to do to fix it...

in the "app" folder is a file "store.rb" and this contains the following lines...

ActiveRecord::Base.establish_connection(   :adapter => 'sqlite3',   :database => 'db/development.sqlite3')

It is these lines that are causing the problem since I am not using sqlite3 but rather mysql2.

I don't know how to fix this. I tried the following...

ActiveRecord::Base.establish_connection(   :adapter => 'mysql2',   :database => 'db/development.mysql2')

But that produced a new set of errors.

Any advice most welcome.

No kidding -- " :database => 'db/development.mysql2' " is certainly one problem. Do you not have a config/database.yml entry for your actual DB that works? To compare to?

If not, you'll have to get that sorted first.

Presumably you do not know why store.rb is attempting to open a separate connect to the (or a different) database. Presumably also you inherited this code. If you cannot contact the original developer or do not have documentation for it then you are just going to have to slog through the code trying to work it out. Personally I would start by just removing that code and see what happens (or even remove store.rb, what is it doing in the app folder anyway?). If you have tests then see if they run, otherwise write them.

Colin

OK. I now know why this is happening but I don't know what to do to fix it...

in the "app" folder is a file "store.rb" and this contains the following lines...

ActiveRecord::Base.establish_connection( :adapter => 'sqlite3', :database => 'db/development.sqlite3')

To quote from your OP

And a search of my project shows no files containing any reference to sqlite3.

??

Colin

Colin Law wrote in post #964785:

To quote from your OP

And a search of my project shows no files containing any reference to sqlite3.

What can I say? Windows 7 search is not too good. It brought up files that mentioned the target words in comments but it did not bring up this particular file. Because it brought back some files, and those files were lower down than the root, I assumed it had brought back all such files from all levels. Windows XP would have done that - no problem - but not it appears Windows 7.

Today I trawled through each file that looked like it might have something to do with configuration by hand (effectively doing the search myself) and found the one I listed today.

I do have a valid database.yml that works. The problem is the code you're seeing here was downloaded as part of the Agile book and earlier editions of the project did not have this "store.rb" file, that's what drew my attention to it.

My next step was (or maybe is) to scan the book and see if I can find reference to where it was created and why.

A bit more of the code - to clarify the origin...

I seriously suggest considering switching to Ubuntu (or similar). You would not regret it. It seems possible that the time you have spent trying to sort this problem would have covered getting you up and running in Ubuntu.

Also I would suggest using a decent editor such as jEdit (others are available) that supports sets of files (projects) and includes source search that in this case in a few seconds would have found all references to sqlite. jEdit will run on Windows.

Colin

A bit more of the code - to clarify the origin...

utterly irrrelevant.

:database => 'db/development.mysql2')

The line above is *wrong* -- look at your config/database.yml entries and compare. That is simply not a valid MySQL entry.

Colin Law wrote in post #964799:

I seriously suggest considering switching to Ubuntu (or similar). You would not regret it...

I am doing the tutorials in parallel on Ubuntu. Unfortunately the "test functionals" issue I mentioned above that started me down this path occurs there too.

My primary development platform has to be Windows I'm afraid - that's what my customers want - but I do as much as possible on Ubuntu as well. :slight_smile:

Hassan Schroeder wrote in post #964802:

A bit more of the code - to clarify the origin...

utterly irrrelevant.

:database => 'db/development.mysql2')

The line above is *wrong* -- look at your config/database.yml entries and compare. That is simply not a valid MySQL entry.

-- Hassan Schroeder ------------------------ hassan.schroeder@gmail.com twitter: @hassan

Hi Hassan,

The relevance was to show the full title and version number of the book from which this example code is taken, especially since I know many others are also reading and following that book and are having similar problems. Since many consider it the definitive work on Ruby on Rails then I think it's worth mentioning it. I agree the actual additional code shown beyond the comments in the header adds nothing to the problem analysis. :slight_smile:

I know that line is wrong - Rails tells me that - what I don't know is how to fix it, or even why the store.rb file exists at all in the app folder.

However I downloaded this code from the web site associated with the book and that's why it's in there. The original code from the book uses sqlite but I prefer mysql and so changed it to use mysql.

Following the book, and creating my own project, I don't encounter this problem. But I do encounter a serious problem on "test functionals" where the db tables are created, seeded, and then promptly dropped prior to the first test running so all the tests fail. The applicaiton itself works fine.

So as one particular way of investigating this I decided to download the code from the book, reconfigure it for mysql, and see if the testing problem still exists. However I can't get beyond the db:migrate because of this problem being explored here.

Unfortunately, although I've spent many hours on RoR on both Windows 7 and Ubuntu, the Rails aspects of it are IMHO poorly documented. Ruby language - yes good documentaiton and I understand that with no problem. But Rails is unusual in that you can place pieces of an Object in many places and they all come together at runtime, but if that fails to integrate properly then you're pretty much reliant on helpful guys like yourself online pointing you in the right direction.

I am working my way through...

(a) Agile Web Development with Rails Ed.4 (b) Rails Recipes (c) RailsSpace: Building a Social Networking Website with Ruby on Rails (d) Beginning Ruby on Rails E-Commerce

building all of the examples. But in each case I'm encountering problems and issues.

So if I can solve why "test functionals" keeps dropping the tables before running the tests then that would be the biggest help.

I realise that test mode is supposed to start with an empty database so that the tests always run the same. It then creates the tables, then it seeds them, then for some reason it drops the tables and runs the first test which failes because the tables don't exist.

I may be wrong here but I think it used to work before the seeds were written. That it was after the book covered seeds and the seeds file was created that this testing problem occured.

It might also have something to do with using mysql with myisam files because the transaction capability is different according to the Rails books (although I've not noticed that in the past).

Kind Regards Steve