Drew
Drew

Reputation: 338

Rails keeps trying to use SQLite , despite that I've configured MySQL for my project

I setup my rails project "tracks" using:

$ rails --database=mysql tracks # OK
$ cd tracks
$ vim config/database.yml # correct using mysql adapter, added password spec
$ rake db:create RAILS_ENV='development' # OK
$ rake db:migrate # OK

$ ruby script/generate scaffold user name:string password:string email:string url:string # OK
$ rake db:migrate # OK, creates table
$ ruby script/server # OK, starts WEBrick

I open up the thing in a web browser:

http://localhost:3000 # correctly shows the rails welcome splash

I navigate to

http://localhost:3000/users/new

and get a huge slew of errors:

ActiveRecord::StatementInvalid in UsersController#index

SQLite3::SQLException: no such table: users: SELECT * FROM "users" 
RAILS_ROOT: /home/drew/tracks/trunk/tracks

Application Trace | Framework Trace | Full Trace
vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:188:in `log'
vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb:132:in `execute'
vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb:372:in `catch_schema_changes'
vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb:132:in `execute'
vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb:275:in `select'
vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all_without_query_cache'
vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:60:in `select_all'
vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:81:in `cache_sql'
vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:60:in `select_all'
vendor/rails/activerecord/lib/active_record/base.rb:635:in `find_by_sql'
vendor/rails/activerecord/lib/active_record/base.rb:1490:in `find_every'
vendor/rails/activerecord/lib/active_record/base.rb:589:in `find'
app/controllers/users_controller.rb:5:in `index'

wtf? Why is ruby still trying to use SQLite? database.yml has zero mention of SQLite.

Thanks

Upvotes: 2

Views: 663

Answers (5)

dev404
dev404

Reputation: 1098

Don't mean to necro, but if someone runs onto this problem, edit your config/database.yml file, and remove the line that says << default from the production section. What this is doing is loading the default environment first, so Passenger loads it instead of whatever else you've configured.

Upvotes: 0

Ken Fehling
Ken Fehling

Reputation: 2111

As odd as it might sound, try clearing your browser's cookies. I had a similar problem moving from sqlite to postgresql and vice versa. It turns out the stored cookie or session was somehow making the server get stuck in using the old database. If this works then you'll want to take steps on your server to invalidate any existing cookies in your users' browsers.

Upvotes: 0

Calorus
Calorus

Reputation: 11

Had this problem, I found all of the files using "find . | xargs grep 'sqlite3' -sl then replaced all of the yml and rb files it found then restarted the server.

Unfortunately, I don't know which (if any, as it may have been the server restart) solved the issue, but now I'm on and up.

Hope that helps someone, however 'hacky'.

Upvotes: 1

mjeason
mjeason

Reputation: 3

Quick Fix that i've used is...

When i start a project a specify the -d for database

rails -d mysql ProjectName

Which builds the database.yml file for mysql

hope this helps.

Upvotes: 0

Drew
Drew

Reputation: 338

Couldn't figure it out. I ended up reinstalling the OS on the VM and trying again and it worked.

FYI: Do not install rubygems from a package manager like apt-get. Compile it from source or it will all end in tears.

Upvotes: 1

Related Questions