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.

On 24 November 2010 20:28, Steve M. [email protected] wrote:

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 L. 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.

On 24 November 2010 20:57, Steve M. [email protected] wrote:

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?

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

Steve M. 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

Luciano S. wrote in post #963685:

post your Gemfile and database.yml in pastie.org

Done
http://pastie.org/1325155

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

Kind Regards
Steve

post your Gemfile and database.yml in pastie.org

Best Regards,
Luciano S.
http://www.lucianosousa.net
http://twitter.com/lucianosousa
http://rubyonrio.org
*Ruby on Rails Developer
*Linux User #456387
*Contact: +55 21 8418-5945

2010/11/24 Steve M. [email protected]

its ok!
the config not have problem…
;s

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

Best Regards,
Luciano S.
http://www.lucianosousa.net
http://twitter.com/lucianosousa
http://rubyonrio.org
*Ruby on Rails Developer
*Linux User #456387
*Contact: +55 21 8418-5945

2010/11/25 Colin L. [email protected]

On 25 November 2010 10:05, Steve M. [email protected] wrote:

Luciano S. wrote in post #963685:

post your Gemfile and database.yml in pastie.org

Done

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

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

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’)

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.

Luciano S. wrote in post #963876:

post your rake db:migrate --trace…

Done. http://pastie.org/1325873

Kind Regards
Steve

On 29 November 2010 16:08, Steve M. [email protected] wrote:

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’)

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

On 29 November 2010 16:08, Steve M. [email protected] wrote:

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

On Mon, Nov 29, 2010 at 8:08 AM, Steve M. [email protected]
wrote:

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.

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.


Hassan S. ------------------------ [email protected]
twitter: @hassan

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

#—

Excerpted from “Agile Web D. with Rails, 4rd Ed.”,

published by The Pragmatic Bookshelf.

Copyrights apply to this code. It may not be used to create training

material,

courses, books, articles, and the like. Contact us if you are in

doubt.

We make no guarantees that this code is fit for any purpose.

Visit https://pragprog.com/titles/rails4/agile-web-development-with-rails-4/ for more book

information.
#—
require ‘builder’
require ‘active_record’

#ActiveRecord::Base.establish_connection(

:adapter => ‘sqlite3’,

:database => ‘db/development.sqlite3’)

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

On 29 November 2010 16:33, Steve M. [email protected] wrote:

but not it appears Windows 7.
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

Colin L. 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.

On Mon, Nov 29, 2010 at 8:35 AM, Steve M. [email protected]
wrote:

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 S. ------------------------ [email protected]
twitter: @hassan

Colin L. 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:

On Mon, Nov 29, 2010 at 9:48 AM, Steve M. [email protected]
wrote:

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

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.

And I’ve told you twice how to fix it. Seriously, WTF?


Hassan S. ------------------------ [email protected]
twitter: @hassan