RoR migration mysql2 gem - ruby-on-rails

I'm going through a RoR tutorial, but when I try to run a migration it returns
...
*** About to add an index ***
--add_index("admin_users", "username")
rake aborted!
An error has occurred, all later migrations canceled:
invalid date
Looking around online it seems the problem is with the mysql2 gem and "add_index". How should I fix it? I tried uninstalling the mysql2 gem and changing the database.yml file to use mysql but it returned
"Please install the mysql adapter: 'gem install activerecord-mysql-adapter'"
which it then couldn't find.
I'm using Windows Vista, Rails 3.2.1 and the mysql2 gem is 0.3.11 x86-mingw32 and the mysql gem is 2.8.1 x86-mingw32.

We use mysql, just check if this setup works
in GEM file
gem 'rails', '2.3.2'
gem 'mysql', '2.7'
in database.yml
development:
adapter: mysql
encoding: utf8
reconnect: false
database: <database name>
pool: 5
username: <user name>
password: <password>
host: localhost

Related

I can't figure how to install postgresql10.7 in ruby on rails on windows8.1

While going through Michael Hartl's book on RubyonRails, I decided to go with postgresql instead of the sqlite3 version used in the book(Although, I can't get the sqlite3 gem install in RubyonRails but am less concern since my focus is on using pg) and this are the steps I have taken so far
Step1: I downloaded the postgreSQL version 10.7 and installed it
Step2: Add The path to the path environment
Step3: I added it to the
Gemfile
like this
'pg', '~>10.7'
Step4: Run
Rails bundle
WHAT I GOT FROM THE CONSOLE
Could not find gem 'pg (= 10.7) x64-mingw32' in any of the gem sources listed in
your Gemfile.
My question is how can I install the version or any other version of pg on Ruby on Rails in windows
Finally, have been able to figure it out myself and these are what I do
I comment out the sqlite3 like this
gem install 'sqlite3'
replace it with
gem install 'pg'
after that, I go to
config folder
and select the
database.yml
and change the settings to these
default: &default
adapter: postgresql
encoding: unicode
host: localhost
username: postgresql
password: your password
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
development:
<<: *default
database: db_dating
test:
<<: *default
database: db_dating_test
The name of the database I created is called
db_dating
so remember to change yours to your db name

Ruby on Rails - could not load postgres adapter

Building a rails app on heroku (locally). Following their tutorials for rails, and installing postgres locally.
When ever I run the server or generate a migration I get the following err:
LoadError (Could not load 'active_record/connection_adapters/posgtres_adapter'. Make sure that the adapter in config/database.yml is valid. If you use an adapter other than 'mysql', 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapter gem to the Gemfile.):
database.yml:
default: &default
adapter: postgresql
encoding: unicode
pool: 5
development:
<<: *default
database: myapp_development
username: Name
password: secret
host: localhost
Gem file has: gem 'rails' '4.2.0', and gem 'pg' installed
my machine's OS: Windows 64x
Any and all help appreciated.
Doubtful this is the same issue you are having but, posting these details in case it gives a lead. I'm using Windows 10
I had the same error message. To troubleshoot, I tried to do a reinstall of pg with 'gem install pg' but a file was locked.
Found I had a process still using one of the PG files and shut down the process, deleted the entire pg directory found at C:\Ruby200-x64\lib\ruby\gems\2.0.0\gems\pg-0.18.3-x64-mingw32
Reran 'gem install pg' rake db:setup, rake db:create, rake db:migrate and the error was gone.

gem 'pg' can't be loaded only for rails application

I am using pg gem pg-0.17.1-x86-mingw32. It is working fine when i am connecting it from my ruby codes.But when i am trying to connect it via rails apps, it gives me an error::
"Specified 'postgresql' for database adapter, but the gem is not loaded. Add gem 'pg' to your Gemfile."
I am gettigng this error at the time of executing:: "rake db:migrate"
after changing the database.yml
My yml looks like::
development:
adapter: postgresql
database: postgres
host: localhost
user: postgres
password: postgre90
pool: 5
timeout: 5000
I am using::
Rails -4.0.4
Ruby -1.9.3
Please help.. I am a newbie in ruby on rails

Rails 4 postgres bug - cannot create database because the pg gem "is missing", but it is not

I use rails edge (4.0) and when executing:
bundle exec rake db:create
I get
Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile.
I do have "gem pg" in my Gemfile and I have run bundle install...
what could be the reason for this?
thank you
The problem was that I was using an old version of pg gem (0.9.0), newer versions work as expected!
For me, works without user/pass, and using host settings on config/database.yml
defatul: &default
adapter: postgresql
encoding: utf-8
host: localhost
pool: 5
development:
<<: *default
database: appname_development
test:
<<: *default
database: appname_test

Error when loading or migrating database in rails

Whenever I try to use rake db:schema:load or rake db:migrate, I get keep getting the following error:
The bundled mysql.rb driver has been removed from Rails 2.2.
Please install the mysql gem and try again: gem install mysql.
rake aborted!
no such file to load — mysql
I already have the mysql gem installed which is version 2.8.1. Am I missing something?
database.yml
development:
adapter: mysql
database: db_development
host: localhost
username: root
password: password
encoding: utf8
socket: /Applications/rubystack/mysql/tmp/mysql.sock
Try installing mysql2 gem
sudo gem install mysql2
If you are on Rails 3, add
gem 'mysql2'
to your Gemfile & run
bundle install
And change the adapter to mysql2 in your database.yml. I solved many problems with this, might solve yours too.

Resources