I'm new of rails, and i have this big problem. I'm running rails 3.2.9 and Ruby 1.9.3, I did a porting of a rails app from linux to windows, but in windows i'm having a lot of problems with mysql2 gem.
I installed mysql2 gem yesterday and than i tried to run rake db:migrate but i have this output:
rake aborted!
Please install the mysql2 adapter: gem install activerecord-mysql2-adapter (cannot load such file -- mysql2)
C:/Users/RoccaA/Desktop/project/config/environment.rb:5:in `'
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)
Then this is my Gemfile
gem 'rails', '3.2.9'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
#gem 'sqlite3'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
# gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
# gem 'uglifier', '>= 1.0.3'
end
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
gem 'jquery-rails'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'debugger'
# this gems needs for auth
gem 'cancan'
gem 'devise'
gem 'rolify'
gem 'execjs'
gem 'therubyracer', :platform => :ruby
gem 'populator'
gem 'faker'
gem 'paperclip'
gem 'simple_xlsx_writer'
gem 'roo'
gem 'mysql2', '0.3.11'
gem 'simple_xlsx_writer'
gem 'rake', '~> 10.0.4'
gem 'icalendar'
And this is my database.yml
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: emc
pool: 5
username: root
password: root
socket: /var/run/mysqld/mysqld.sock
testing:
adapter: mysql2
encoding: utf8
reconnect: false
database: emc
pool: 5
username: root
password: root
socket: /var/run/mysqld/mysqld.sock
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: emc
pool: 5
username: root
password: root
socket: /var/run/mysqld/mysqld.sock
I tried to solve this problem in a lots of ways, i read that i have to use mysql2 version < 0.3 but with this version I have this output
WARNING: This version of mysql2 (0.2.18) isn't compatible with Rails 3.1 as the ActiveRecord adapter was pulled into Rails itself.
WARNING: Please use the 0.3.x (or greater) releases if you plan on using it in Rails >= 3.1.x
rake aborted!
undefined method `accept' for nil:NilClass
Tasks: TOP => db:migrate
(See full trace by running task with --trace)**
Hope someone can help me, thanks.
Try this to you gemfile
instead of using:
gem 'mysql2', '0.3.11'
use this:
gem 'mysql2'
This is working for me.
And by the way you have duplicate gem
gem 'simple_xlsx_writer'
Forget about it.Insted of it use rails installer from http://www.railsinstaller.org/ it will automatically install mysql2 with ruby and rails with latest versions
Installing Rails and the mysql2 gem in windows is not as easy as on other os. But i found a good answer to your question:
Unable to install MySQL2 gem on Windows 7
The best thing to do is, to install rails on windows with the rubyinstaller.
gem "mysql2", "~> 0.3.11"
and then bundle install
Good detailed steps here => http://blog.mmediasys.com/2011/07/07/installing-mysql-on-windows-7-x64-and-using-ruby-with-it/
Some key points are installing the right version of mysql, the dot net connector, and the gem. Also be sure to place the libmysql file in the correct place.
Related
I deleted postgres from my machine by
brew rm postgresql --force
rm -rf /usr/local/var/postgres
I created a new rails app. This is my standard gemfile
source 'https://rubygems.org'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
gem 'sqlite3'
gem 'puma', '~> 3.0'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.2'
gem 'jquery-rails'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.5'
group :development, :test do
gem 'byebug', platform: :mri
end
group :development do
gem 'web-console'
gem 'listen', '~> 3.0.5'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
Then
bundle install
rails s
Although I haven't specified any pg gem in my gemfile I am getting the error when trying to get to localhost
> Specified 'postgresql' for database adapter, but the gem is not loaded.
> Add `gem 'pg'` to your Gemfile
> (and ensure its version is at the minimum required by ActiveRecord).
> Extracted source (around line #176):
require path_to_adapter
rescue Gem::LoadError => eraise Gem::LoadError,
"Specified '#{spec[:adapter]}' for database adapter,
but the gem is not loaded.
Add `gem '#{e.name}'` to your Gemfile
(and ensure its version is at the minimum required by ActiveRecord)."
rescue LoadError => eraise LoadError,
"Could not load '#{path_to_adapter}'.
Make sure that the adapter in config/database.yml is valid.
If you use an adapter other than 'mysql2', 'postgresql' or 'sqlite3'
add the necessary adapter gem to the Gemfile.", e.backtrace
end
This is my database.yml file which doesn'r include any postgres either.
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3
What's the problem here? Before I was using sqlite in dev and test, and pg in production. There still seem to be some references in the system which I obviously couldn't get rid of.
I have the same problem.
Write in your console:
echo $DATABASE_URL
IF RESULT IS:
postgresql://user:password#localhost/database
Look for in your .bash_profile or .profile
export DATABASE_URL="postgresql://user:password#localhost/database"
Comment this line and to be happy.
Read here
http://edgeguides.rubyonrails.org/configuring.html
Section 3.5
"When duplicate connection information is provided the environment variable (DATABASE_URL) will take precedence"
You still have postgres listed as your adaptor in your database.yml file. Once you change your database.yml to reflect the fact that you are not using postgres you will need to run rake db:drop db:create db:migrate
I'm using mysql2 on Ruby on Rails, following Ruby on Rails 4 Essential Training by Kevin Skoglund, and I'm on the early chapters where it tells me to access the project by typing 'rails server' and opening 'localhost:3000' on my browser.
Problem is this:
Connection not Established
So I cannot access my project, and can't move on with the tutorials.
Also, I noticed something different between my and the tutorial's terminal. In my terminal, before booting WEBrick, it shows this:
/home/jmmaglinao16/.rvm/gems/ruby-2.3.0/gems/activesupport-4.0.0/lib/active_support/values/time_zone.rb:282: warning: circular argument reference - now
I'm not sure if it has any connection to the problem but that's what I have so far. Please help me guys. Thank you.
Gemfile:
source 'rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0'
# Use mysql as the database for Active Record
gem 'mysql2'
# Use SCSS for stylesheets
#gem 'sass-rails', '~> 4.0.0'
# Use Uglifier as compressor for JavaScript assets
#gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
#gem 'coffee-rails', '~> 4.0.0'
# See for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
#gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more:
#gem 'turbolinks'
# Build JSON APIs with ease. Read more:
#gem 'jbuilder', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
Database.yml:
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MYSQL driver
# gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
# gem 'mysql2'
#
# And be sure to use new-style password hashing:
#
development:
adapter: mysql2
encoding: utf8
database: #simple_cms_development
pool: 5
username: root
password: mypass
socket: /var/run/mysqld/mysqld.sock
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: mysql2
encoding: utf8
database: simple_cms_test
pool: 5
username: root
password: mypass
socket: /var/run/mysqld/mysqld.sock
production:
adapter: mysql2
encoding: utf8
database: simple_cms_production
pool: 5
username: root
password: mypass
socket: /var/run/mysqld/mysqld.sock
Try putting the '#' in the beginning of the line like here:
#database: simple_cms_development
I am using heroku in a rails blog. After being able to fix the gem file following many related answers here, and being able to push my blog to heroku the app is not working locally.
I have change 'sqlite3' for 'pg' in my production env and add 'sqilte3' only in development test, push my changes to git and after to heroku. So far it was working but when I try to run the rails server, is asking me for 'sqlite3' again.
Error:
rb:177:in rescue in spec': Specified 'sqlite3' for database adapter, but the gem is not loaded. Addgem 'sqlite3'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError)
GEMFILE
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.4'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'devise'
gem 'will_paginate', '~> 3.0.5'
gem 'cancancan'
gem "paperclip", "~> 5.0.0.beta1"
gem 'ratyrate'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
gem "sqlite3"
gem 'rspec-rails', '~> 3.0'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
group :production do
gem 'rails_12factor'
gem 'pg'
end
DATABASE.YML
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3
I have followed the steps here >> http://railscasts.com/episodes/342-migrating-to-postgresql?view=asciicast >> and is working now. Note for beginners, if you are going to use rails and heroku start you application with pg to save time debugging this.
I know it's a very old question but i got the same issue yesterday, am using Ubuntu 16.04 Rails 5.1.6.
I tried every solution that i found on the web but nothing worked for me, so am writing what solved this issue for me so it can help someone who get into this issue.
Simply check what version of Sqlite3 gem you are using:
bundle show sqlite3
for me it was sqlite3-1.4.0
Now just downgrade to a older version of the sqlite3 gem
Simply add gem 'sqlite3', '~> OLDER VERSION' in your gemfile replacing your current version of sqlite3
bundle install
That's it, it should work.
If you are using pg in production than... why sqlite3 confugration here
production:
<<: *default
database: db/production.sqlite3
update it from pg configuration.
Heroku is not compatible with sqlite3, you should use pg
Pg config.
development:
adapter: postgresql
encoding: unicode
database: blog_development
pool: 5
username: blog
password:
I would suggest removing the whole default section of your database.yml and just set everything for the rest:
development:
adapter: sqlite3
pool: 5
timeout: 5000
database: db/development.sqlite3
test:
adapter: sqlite3
pool: 5
timeout: 5000
database: db/test.sqlite3
production:
adapter: postgresql
encoding: unicode
database: <project name>
username: <%= ENV['USERNAME'] %>
password: <%= ENV['PASSWORD'] %>
I'm new to Rails and was trying to launch my server. Running the command rails server generated an error
Specified 'sqlite3' for database adapter, but the gem is not loaded. Add gem 'sqlite3' to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).
I looked at many of these previous questions and none seems to solve it. Here is my Gemfile code
if RUBY_VERSION =~ /1.9/
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
end
source 'https://rubygems.org'
gem 'rails', '~> 4.2.0'
gem 'ey_config'
gem 'rails_autolink'
gem 'simple_form'
# Assets
gem 'jquery-rails'
gem 'sass-rails'
gem 'coffee-rails'
gem 'uglifier'
platform :ruby do
gem 'mysql2'
gem 'pg'
gem 'activerecord-postgis-adapter', '3.0.0.beta2'
gem 'sqlite3'
gem 'newrelic_rpm'
gem 'unicorn'
gem 'puma'
gem 'json'
gem 'minitest'
gem 'psych'
gem 'racc'
end
platforms :jruby do
ar_jdbc_version = '~> 1.3'
gem 'activerecord-jdbc-adapter', ar_jdbc_version
gem 'activerecord-jdbcmysql-adapter', ar_jdbc_version
gem 'activerecord-jdbcpostgresql-adapter', ar_jdbc_version
gem 'activerecord-jdbcsqlite3-adapter', ar_jdbc_version
gem 'jdbc-mysql', :require => false
gem 'jdbc-sqlite3', :require => false
gem 'jdbc-postgres', :require => false
gem 'jruby-openssl'
gem 'trinidad'
end
platform :rbx do
gem 'rubysl'
gem 'rubysl-test-unit', :require => false
end
# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
group :development, :test do
gem 'tzinfo-data'
end
And here is my database.yml file
# SQLite version 3.x
# gem install sqlite3
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000`
Here is the code in my rakefile:
# 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'
Listr::Application.load_tasks
task :travis => ['db:create:all', 'db:migrate', :default]
It will be also appreciated for providing any explanation accompanying the answer. Thanks.
Your sqlite3 gem is not being loaded in production, because of the version mismatch. so, update you gemfile as gem 'sqlite3', '~> 1.3.13' it'll work. Keep it under group :production, :test It'll be good when you push your code to heroku.
Your sqlite3 gem is not being loaded, because of where you've got it in the Gemfile. Take it out of platform :ruby do and place it outside of that block , May be right under gem 'rails', '~> 4.2.0'
I have the following error when I try to run
git heroku push master
I don't how solve the problem. I am using rails 3.2.19
fernando#fernando:~/ProyectoTicketMaster/Ticket_Master$ git push heroku master
Preparing app for Rails asset pipeline
Running: rake assets:precompile
Connecting to database specified by DATABASE_URL
rake aborted!
PG::ConnectionBad: could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
/tmp/build_dd87fdc88ebb265d09b8212e3b0df10b/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.19/lib/active_record/connection_adapters/postgresql_adapter.rb:1222:in `initialize'
/tmp/build_dd87fdc88ebb265d09b8212e3b0df10b/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.19/lib/active_record/connection_adapters/postgresql_adapter.rb:1222:in `new'
/tmp/build_dd87fdc88ebb265d09b8212e3b0df10b/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.19/lib/active_record/connection_adapters/postgresql_adapter.rb:1222:in `connect'
this is my GemFile. I'm using pg for production and sqlite for development. Here attached my GemFile and my databse.yml
source 'https://rubygems.org'
gem 'rails', '3.2.19'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
group :development, :test do
gem 'sqlite3', '1.3.9'
end
group :production do
gem 'pg', '0.17.1'
gem 'rails_12factor', '0.0.2'
end
gem 'hirb'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'debugger'
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
Several things might cause this problem.
Do you have postgres running? Have you added it to your server?
Have you installed gem for pg?
Your setup should look like:
development:
adapter: postgresql
host: localhost
username: user
database: app-dev
You can take a look at this link: https://devcenter.heroku.com/articles/heroku-postgresql#connecting-in-ruby, it will probably help :)
NOTE:: This should be comment but I don't have enough repoutation to comment.
Adding the following line in config/application.rb was the solution to my problem
config.assets.initialize_on_precompile = false