Thinking Sphinx mistakenly looks for mysql instead of postgresql - ruby-on-rails

My database.yml file and my Gemfile specify the use of postgresql. However, when I run
rake ts:index
I get the error
rake aborted!
cannot load such file -- mysql2
Why is Thinking Sphinx looking for mysql?

mysql2 gem is required for connecting to Sphinx, so please include it even if you're using PostgreSQL as your database.
Reference:
https://github.com/pat/thinking-sphinx

Related

heroku deploy error in RoR(Github deploy) what should I do with postgresql error?

I'm deploying small app from C9 to github then to Heroku!
In heroku deploy dashboard, it says it's been deployed, but when I open the app, it just gives me error msg.
So I searched a lot of Stackoverflow answers and was following the direction from Heroku website(https://devcenter.heroku.com/articles/sqlite3) to remove sqlite3 and install the gem pg.
I did replace gem 'sqlite3' to gem 'pg' and did 'bundle install', and then
It says I need to convert my config/database.yml file, So I replaced it like this:
development:
adapter: postgresql
database: my_database_development
pool: 5
timeout: 5000
test:
adapter: postgresql
database: my_database_test
pool: 5
timeout: 5000
production:
adapter: postgresql
database: my_database_production
pool: 5
timeout: 5000
and then when I come back to c9 bash and type 'rake db:create',
it shows me
**rake aborted!
ActiveRecord::NoDatabaseError: FATAL: database "my_database_development" does not exist**
this error.
someone said 'bundle exec rake db:setup' would work, so I did, and then it shows
**Couldn't create database for {"adapter"=>"postgresql", "database"=>"my_database_test", "pool"=>5, "timeout"=>5000}
/home/ubuntu/workspace/db/schema.rb doesn't exist yet. Run `rake db:migrate` to create it, then try again. If you do not intend to use a database, you should instead alter /home/ubuntu/workspace/config/application.rb to limit the frameworks that will be loaded.**
I don't know how to react to this msg.... when I type 'rake db:migrate' and it shows this again.
rake aborted!
ActiveRecord::NoDatabaseError: FATAL: database "my_database_development" does not exist
I'm not using database, so maybe I can try something on 'config/application.rb' file, but how should I do??
It wasn't necessary to change your development and test databases, those could still have used sqlite3 and so your C9 instance would have continued to work.
(Although there are some advantages to using a consistent adapter across all environments)
If this is just a hobby exercise I would be tempted to keep sqlite3 for development and test.
Also, Heroku replaces the database.yml with its own version so you don't need a production stanza in database.yml
You do need the pg gem, but you can specify it is only loaded in production and you can specify the sqlite3 gem is only loaded in development and test. Do that in your Gemfile and then bundle.
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
If you want to use PostgreSQL in your C9 instance, you have to install PostgreSQL (the database, not just the adapter). It's not a simple process.
This wiki explains how you would install it.
https://wiki.postgresql.org/wiki/Detailed_installation_guides
one of the solution that you can create database manually this is easily solut

Rake assuming wrong database engine?

I have adapter set to "mysql2" in my database.yml, yet when I try to deploy to Heroku, I get an error telling me, that I don't have Postgres installed... What the heck?
Gem::LoadError: Specified 'postgresql' for database adapter, but the gem is not loaded.
Heroku works ONLY WITH POSTGRESQL
you should add postgresql to envirement what you use on Heroku
UPDATED
but Heroku has huck for MySQL:
TAKE A LOOK

Rails 4 - how to use sqlite3 in development and PostgreSQL in production w/Heroku

I am trying to deploy to Heroku but can't because the default sqlite3 server is still in place.
Detected sqlite3 gem which is not supported on Heroku.
https://devcenter.heroku.com/articles/sqlite3
In another tutorial with Rails 3.2.13 I was able to use sqlite3 as the dev db and Postgres as the production db. The Gemfile looks different in Rails 4 but I have modified it to have this:
group :development do
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
end
group :production do
gem 'pg'
end
I then changed my database.yml file so that the production section looked like this:
production:
adapter: postgresql
database: my_production_database
pool: 5
timeout: 5000
I then ran bundle install and rake db:create and rake db:migrate but am still unable to push to Heroku. So I tried rake db:drop as well as rake db:create and rake db:migrate but am still getting the same error message.
Am I missing something? What else do I need to do to make sure I'm getting Postgres as my production database and am able to use Heroku?
Don't do it. You are just going to run into problems down the road. Use the same database in production and development. There are a lot of resources available in documenting the switch from a sqlite to postgres database.
Take the time and switch.
Have a look at this Rails Cast.
http://railscasts.com/episodes/342-migrating-to-postgresql?view=asciicast
Try using this for your production DB
production:
adapter: postgresql
host: localhost
encoding: unicode
database: my_production_database
pool: 5
username:
password:
You can leave username and password blank

Rails:: rake db:create does not return anything on Rails 3.0.3 and Ruby 1.9.2

I have following configuration:
Ruby version 1.9.2 (i386-mingw32)
RubyGems version 1.7.2
Rack version 1.2
Rails version 3.0.3
Active Record version 3.0.1
Action Pack version 3.0.3
Active Resource version 3.0.3
Action Mailer version 3.0.3
Active Support version 3.0.3
I am running rake db:create command but it returns nothing and using trace, I find following output on the screen
E:\Crawler\server>rake db:create --trace
** Invoke db:create (first_time)
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
** Execute db:create
rake aborted!
C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.2.7/lib/active_record/connection_adapters/mysql2_adapter.rb:312:in `query'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.2.7/lib/active_record/connection_adapters/mysql2_adapter.rb:312:in `execute
When I run rake db:migrate command, it returns following:
E:\Crawler\server> rake db:migrate
rake aborted!
Unknown database 'marketplace_development'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
My rake file is:
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
require 'rake'
module ::Marketplace
class Application
include Rake::DSL
end
end
module ::RakeFileUtils
extend Rake::FileUtilsExt
end
Marketplace::Application.load_tasks
database.yml file:
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
# gem install mysql2
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: Marketplace_development
pool: 5
username: root
password:
socket: /tmp/mysql.sock
Can anybody tell me what's happening here? I have not created any database explicitly on my own. Do I need to create a database with some tool? I have seen other SO threads but no avail.
Edit1::
As suggested by Rogier, I opened up MySQL command line client and ran following command
create schema marketplace_development;
Now both commands db:create and db:migrate hang up upon execution.
Edit2::
Every time I restart my command window and start a server with rails server, it asks me to install now ActiveRecord mysql2. I install with gem install activerecord-msql2-adpater, uninstall mysql2 (0.3.11-x86-ming32) , update my Gemfile.lock file to just have mysql2 (0.2.7) .
I run bundle install and start my rails server which is started successfully. But I am not able to view the server in browser. http://localhost:3000 and http://127.0.0.1:3000 never return the page. I have tried with port 30001 also, but in vain.
Edit3
I stopped my server, created a new rails project rails new myApp , moved into folder myApp and started the server. It asked me to do bundle install because it couldn't find sqlite3 ruby. I did so, and started the server and I was able to browse it through above URL.
I moved to my previous server folder and it still doesn't work. What could be wrong in this application?
After making Edit3, I realized that there might be something wrong with my own project in terms of required dependencies. During the course of installation, I faced many issues and to solve them, I tried every tip given on SO and other forums without knowing even if it's compatible with my existing installation or not. Initially I installed Ruby 1.8.7 and rails 3.1.x without looking at Gemfile, which as a newbie I didn't know its purpose. Then I installed Ruby 1.9.2 and started doing random installations.
And on them was installation of rake 10.0.2 while my project required rake 0.8.7. Since I didn't know much about which rails server is compatible with which version of Ruby, I was trying installation whatever was given on internet, desperately wanting it to be working. Bad thing to do!!
Solution:
I uninstalled rake 10.0.2 and went back to rake 0.8.7. This solution helped me to get it working. Uninstalled mysql (0.3.11) and installed mysql2 (0.2.7)
Lesson learnt: Don't do random installations without looking at project requirements.
Keep your db name lowercase (mysql can be case sensitive).
You can create a db simple by using mysql command:
mysql -u root -p
create schema marketplace_development;
quit
the above command is anyway useful to check if the credentials are working properly.
see if the migration then works.
db:create should create the db for you
for all db tasks:
rake -T db
try this basic example:
// im running
MySQL 5.5.25-log
Rails 3.2.2
// from the command line try this
rails new my_sql_test -d mysql
// if the gems are not installed, then run:
bundle install
// update your user/pass
rake db:create
// you get no response
mysql -u root
show schemas;
// schema is created?
If your username is root, and password is not for the root. Change the database.yml file as follows:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: Marketplace_development
pool: 5
host: localhost
username: root
password:
I think, the above will work for you. Go ahead.

rails 3.1.3: rake aborts (couldn't parse YAML) when run first db:migrate (trying to run postgres locally on mac lion)

For a new project I'm trying to run postgres locally.
Mac Lion has Postgres installed (9.1.2). I modified my path in .bash_profile (per another SO thread) so now I have no trouble creating a database or user using the psql utility.
I uninstalled and re-installed the pg gem (0.13.2) using env ARCHFLAGS="-arch x86_64" gem install pg per the excellent blog at http://blog.willj.net/2011/05/31/setting-up-postgresql-for-ruby-on-rails-development-on-os-x/
My Gemfile uses the pg gem for development, test, and production. I've run bundle install.
My database.yml looks like this (and the username and database names are correct and I verified I can access the database fr that username using the psql utility):
development:
adapter: postgresql
encoding: unicode
database: ddchart_development
pool: 5
username: ddchart
password:
(same for test and production, except _test and _production. Password is blank, right?)
When I run bundle exec rake db:migrate it aborts:
rake aborted!
couldn't parse YAML at line 8 column 10
Any help would be appreciated!
If you pasted the code correctly, there are errors in the code. For example, there's only one space before "adapter", but two before following lines.
In YAML, indentation matters.

Resources