# Sqlite3 test fails in Rails app

**URL:** <https://www.ruby-forum.com/t/sqlite3-test-fails-in-rails-app/63479>\
**Category:** Rails\
**Created:** [June 15, 2006, 4:01pm UTC](https://www.ruby-forum.com/t/sqlite3-test-fails-in-rails-app/63479 "2006-06-15T16:01:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tyler\_Morten](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5f8ce5/32.png) [@Tyler\_Morten](https://www.ruby-forum.com/u/Tyler_Morten)\
**Post date:** [June 15, 2006, 4:01pm UTC](https://www.ruby-forum.com/t/sqlite3-test-fails-in-rails-app/63479/1 "2006-06-15T16:01:06Z")

</div>

Greetings:

I am using Sqlite3 database with my Rails app. When I try and run “rake  
tests” for the app it always fails with the error:

\*\* Invoke default (first\_time)  
\*\* Invoke test (first\_time)  
\*\* Execute test  
\*\* Invoke test:units (first\_time)  
\*\* Invoke db:test:prepare (first\_time)  
\*\* Invoke environment (first\_time)  
\*\* Execute environment  
\*\* Execute db:test:prepare  
\*\* Invoke db:test:clone (first\_time)  
\*\* Invoke db:schema:dump (first\_time)  
\*\* Invoke environment  
\*\* Execute db:schema:dump  
\*\* Execute db:test:clone  
\*\* Invoke db:schema:load (first\_time)  
\*\* Invoke environment  
\*\* Execute db:schema:load  
\*\* Invoke test:functionals (first\_time)  
\*\* Invoke db:test:prepare  
\*\* Execute test:functionals  
/usr/bin/ruby18 -Ilib:test  
“/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake/rake\_test\_loader.rb”  
“test/functional/dispatcher\_controller\_test.rb”  
Loaded suite  
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake/rake\_test\_loader Started  
E/usr/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/errors.rb:94:in  
`check': SQL logic error or missing database (SQLite3::SQLException) from /usr/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/resultset.rb:76:in`check’  
from  
/usr/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/resultset.rb:68:in  
`commence' from /usr/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/resultset.rb:61:in`initialize’  
from  
/usr/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/statement.rb:158:in  
`execute' from /usr/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/database.rb:211:in`execute’  
from  
/usr/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/database.rb:186:in  
`prepare' from /usr/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/database.rb:210:in`execute’  
from  
/usr/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/database.rb:620:in  
`rollback' ... 13 levels... from /usr/lib/ruby/1.8/test/unit/autorunner.rb:200:in`run’  
from  
/usr/lib/ruby/1.8/test/unit/autorunner.rb:13:in  
`run' from /usr/lib/ruby/1.8/test/unit.rb:285 from /usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake/rake_test_loader.rb:5 **Invoke test:integration (first_time)** Invoke db:test:prepare ** Execute test:integration /usr/bin/ruby18 -Ilib:test "/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake/rake_test_loader.rb" rake aborted! Test failures /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/tasks/testing.rake:35 /usr/lib/ruby/site_ruby/1.8/rake.rb:387:in`execute’  
/usr/lib/ruby/site\_ruby/1.8/rake.rb:387:in  
`execute' /usr/lib/ruby/site_ruby/1.8/rake.rb:357:in`invoke’  
/usr/lib/ruby/1.8/thread.rb:135:in  
`synchronize' /usr/lib/ruby/site_ruby/1.8/rake.rb:350:in`invoke’  
/usr/lib/ruby/site\_ruby/1.8/rake.rb:364:in  
`invoke_prerequisites' /usr/lib/ruby/site_ruby/1.8/rake.rb:999:in`each’  
/usr/lib/ruby/site\_ruby/1.8/rake.rb:363:in  
`invoke_prerequisites' /usr/lib/ruby/site_ruby/1.8/rake.rb:356:in`invoke’  
/usr/lib/ruby/1.8/thread.rb:135:in  
`synchronize' /usr/lib/ruby/site_ruby/1.8/rake.rb:350:in`invoke’  
/usr/lib/ruby/site\_ruby/1.8/rake.rb:1906:in  
`run' /usr/lib/ruby/site_ruby/1.8/rake.rb:1906:in`run’  
/usr/bin/rake:8

> >

I am at a loss on this one. Is anyone else experiencing the same result  
using Sqlite3? I am using sqlite3-ruby version 1.1.0 and Sqlite3  
version  
3.3.5-r1 on a Gentoo linux system. All of the CRUD actions in my  
application work just fine, so I don’t know why the tests are bombing  
out  
with this error. I am using the correct adapter and dbfile in the  
database.yml file, so the “missing database” error should not be the  
case.

Thanks for your help!

Tyler Morten

---

<div class="post-metadata">

**Author:** ![Tyler\_Morten](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5f8ce5/32.png) [@Tyler\_Morten](https://www.ruby-forum.com/u/Tyler_Morten)\
**Post date:** [June 15, 2006, 4:33pm UTC](https://www.ruby-forum.com/t/sqlite3-test-fails-in-rails-app/63479/2 "2006-06-15T16:33:07Z")

</div>

> I am using Sqlite3 database with my Rails app. When I try and run “rake  
> tests” for the app it always fails with the error:

First, make sure you have this angle covered. It burned me when I  
first starting using sqlite.

[http://code.whytheluckystiff.net/camping/wiki/BeAlertWhenOnSqlite3](http://code.whytheluckystiff.net/camping/wiki/BeAlertWhenOnSqlite3)

-TJ

---

<div class="post-metadata">

**Author:** ![Tyler\_Morten](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5f8ce5/32.png) [@Tyler\_Morten](https://www.ruby-forum.com/u/Tyler_Morten)\
**Post date:** [June 15, 2006, 4:58pm UTC](https://www.ruby-forum.com/t/sqlite3-test-fails-in-rails-app/63479/3 "2006-06-15T16:58:13Z")

</div>

> First, make sure you have this angle covered. It burned me when I  
> first starting using sqlite.
> 
> [http://code.whytheluckystiff.net/camping/wiki/BeAlertWhenOnSqlite3](http://code.whytheluckystiff.net/camping/wiki/BeAlertWhenOnSqlite3)

Thanks for the response, TJ. I am using swig from portage on my Gentoo  
box, and when I do: $gem install sqlite3-ruby it appears to run make  
and  
everything builds fine. However, I am still getting the error only when  
I test. The rest of the app works fine.

I also tried running all tests from memory by setting the dbfile  
“:memory:”, but it still fails. I am wondering if I need to upgrade  
from  
sqlite3 3.3.5 to 3.3.6. Thoughts?

Tyler

---

<div class="post-metadata">

**Author:** ![Tyler\_Morten](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5f8ce5/32.png) [@Tyler\_Morten](https://www.ruby-forum.com/u/Tyler_Morten)\
**Post date:** [June 16, 2006, 1:33am UTC](https://www.ruby-forum.com/t/sqlite3-test-fails-in-rails-app/63479/4 "2006-06-16T01:33:39Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

> I am using Sqlite3 database with my Rails app. When I try and run  
> “rake  
> tests” for the app it always fails with the error:

> /usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake/rake\_test\_loader  
> Started  
> E/usr/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/  
> errors.rb:94:in  
> `check’: SQL logic error or missing database (SQLite3::SQLException)  
> from

I had a similar problem Tyler, hopefully this will help you…

Go into your `tests/test\_helper.rb’ and disable transactional fixtures.

self.use\_transactional\_fixtures = false

You should now see some errors that are less cyrptic then  
‘SQLite3::SQLException’.  
Use this information to try and solve your problem.

Myself, I had an error about the tables not existing! A quick hack to  
the `config/environment.rb` file fixed that…

if ENV[“RAILS\_ENV”] == “test”  
load “#{RAILS\_ROOT}/db/schema.rb”  
end

I’ll try and look into this a little deeper later on today.

Hope this helps!

Luke Antins  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.3 (Darwin)

iD8DBQFEke2cf6ZEiY4w2wYRAsg1AJ9M8pqhvJds2jzzV53YAHKbyx5G9gCfZdU6  
k17iTWVdG2PqC/kIeaiHHBo=  
=s0li  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![Tyler\_Morten](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5f8ce5/32.png) [@Tyler\_Morten](https://www.ruby-forum.com/u/Tyler_Morten)\
**Post date:** [June 16, 2006, 5:59am UTC](https://www.ruby-forum.com/t/sqlite3-test-fails-in-rails-app/63479/5 "2006-06-16T05:59:35Z")

</div>

> if ENV[“RAILS\_ENV”] == “test”  
> load “#{RAILS\_ROOT}/db/schema.rb”  
> end
> 
> I’ll try and look into this a little deeper later on today.
> 
> Hope this helps!
> 
> Luke Antins

Hi Luke,

Thanks for the help. It definitely cleared up the cryptic errors I was  
getting. Unfortunately, now it doesn’t like one of my association  
tables  
and is giving me an error when it tries to create an index about “object  
name reserved for internal use”. Which I find hard to believe that one  
of my “own” named indexes clashes with something in Sqlite…oh well.

It is strange to me, though, that I can test successfully on other  
database platforms. I thought that maybe I was doing something wrong  
and  
have mis-matched versions of sqlite3 on my computer.

Again, thank you for your help. If you have any more tricks up your  
sleeve, let me know. I will also be working on trying to resolve this  
and  
will let the list know if I come up with anything.

Thanks again,

Tyler Morten

---

<div class="post-metadata">

**Author:** ![Tyler\_Morten](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5f8ce5/32.png) [@Tyler\_Morten](https://www.ruby-forum.com/u/Tyler_Morten)\
**Post date:** [June 16, 2006, 11:16am UTC](https://www.ruby-forum.com/t/sqlite3-test-fails-in-rails-app/63479/6 "2006-06-16T11:16:34Z")

</div>

Tyler Morten wrote:

> Greetings:
> 
> I am using Sqlite3 database with my Rails app. When I try and run “rake  
> tests” for the app it always fails with the error:

> SQL logic error or missing database (SQLite3::SQLException)

> I am at a loss on this one.

I have seen the same when I tried to switch to SQLite for testing  
(everything was working great on MySQL).

I have found out that the problem was caused by CSV fixtures. When I  
changed fixture format for join model (the one I was using with has\_many  
:through) from CSV to YAML errors went away.

Funny thing is that only the join model fixture was causing troubles.  
CSV fixtures for tables used by has\_and\_belongs\_to\_many were ok.

Hope this helps.

Regards,

Lukasz (Bragi)

---

<div class="post-metadata">

**Author:** ![Tyler\_Morten](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5f8ce5/32.png) [@Tyler\_Morten](https://www.ruby-forum.com/u/Tyler_Morten)\
**Post date:** [June 16, 2006, 6:11pm UTC](https://www.ruby-forum.com/t/sqlite3-test-fails-in-rails-app/63479/7 "2006-06-16T18:11:04Z")

</div>

> 

Lukasz,

To my knowledge, I am not using CSV fixtures. It appears that I only  
have yaml fixtures…however, I could be mistaken on this, as my  
knowledge of Rails testing is fairly limited right now.

It seems I was able to reslove this issue by first disabling  
transactional  
fixtures in the test\_helper.rb file per Luke’s suggestion. Also, I had  
to  
go into sqlite3 and re-create one of my many-to-many association tables.  
I just dropped it and re-created it and then re-generated a few of the  
model objects. Everything appears to be working now.

Thank you to everyone who helped on this. It is much appreciated.

Tyler Morten
