Topic: Rails 3.1.2 db Migration problem Rake aborted!

Hi,

I have been working with Ruby 1.8.7 with rails 2.3.8 and mysql since last 6
months.
I have just started working with rails '3.1.2' with Ruby 1.9.2
and mysql2.
Just to get hands-on with the new version of rails, I tried creating a
sample application with single scaffold (User username:string
password:string), but it gives the following error on db:migrate :-

==  CreateUsers: migrating
====================================================
-- create_table(:users)
rake aborted!
An error has occurred, all later migrations canceled:

undefined method `rows' for nil:NilClass

Tasks: TOP => db:migrate
(See full trace by running task with --trace)
   -> 0.1100s
==  CreateUsers: migrated (0.1100s)
===========================================


Any suggestions??

When you feel the entire world is against you, there is a little voice in the back of your head that keeps saying... "You can do it, I know you can" That is because you can ♥

Re: Rails 3.1.2 db Migration problem Rake aborted!

Is the database set up?

look in the development.log,  see if any SQL was sent to the database.

My guess is that whatever database you've specified in database.yml doesn't exist in your MySQL database.

Joe got a job, on the day shift, at the Utility Muffin Research Kitchen, arrogantly twisting the sterile canvas snout of a fully charged icing anointment utensil.

Re: Rails 3.1.2 db Migration problem Rake aborted!

Yes, Database setup is fine.

Every When I do rake db:create, it creates the database also.

But Every time i do rake db:migrate i get an error saying "undefined method "rows" for nill:Class". I am using the mysql2 gem  on my windows machine and have installed mysql server 5.1. 

It only creates the database and creates the first table but when it wants to finish the migration of the first table i get the error.

For your information, My database.yml file is-

# 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: zynapp_dev
  pool: 5
  username: root
  password: rootroot
  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
  reconnect: false
  database: zynapp_test
  pool: 5
  username: root
  password: rootroot
  socket: /var/run/mysqld/mysqld.sock

production:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: zynapp_prod
  pool: 5
  username: root
  password: rootroot
  socket: /var/run/mysqld/mysqld.sock

Any help?

When you feel the entire world is against you, there is a little voice in the back of your head that keeps saying... "You can do it, I know you can" That is because you can ♥

Re: Rails 3.1.2 db Migration problem Rake aborted!

Post the actual migration file you are running.

also post any SQL statements that show up in the development.log just prior to it blowing up.

Joe got a job, on the day shift, at the Utility Muffin Research Kitchen, arrogantly twisting the sterile canvas snout of a fully charged icing anointment utensil.

Re: Rails 3.1.2 db Migration problem Rake aborted!

http://stackoverflow.com/questions/6460 … mysql2-gem

I think this will solve your problem

BTW,  simple trick always google the exact error message, leaving off specific like line numbers in your code, etc.

Joe got a job, on the day shift, at the Utility Muffin Research Kitchen, arrogantly twisting the sterile canvas snout of a fully charged icing anointment utensil.

Re: Rails 3.1.2 db Migration problem Rake aborted!

That didn't resolved my problem.
The project was working fine in ubuntu development environment.
But this is Windows Production environment as I am hosting the application to goDaddy Server which is on Windows.
I checked my production.log and it just prints "Migrating to CreateUsers (20120131131022)"

I assume that gemfile is having some gems that are not compatible to Windows. Here in this case, its mysql2.

Although I believe migration files are not the issues, here is my migration file...

My migration file for users is-

class CreateUsers < ActiveRecord::Migration
  def self.up
    create_table :users do |t|
      t.string    :login,               :null => false
      t.string    :email,               :null => false
      t.string    :crypted_password,    :null => false
      t.string    :password_salt,       :null => false
      t.string    :persistence_token,   :null => false
      #t.string    :single_access_token, :null => false                # optional, see Authlogic::Session::Params
      #t.string    :perishable_token,    :null => false                # optional, see Authlogic::Session::Perishability

      # magic fields (all optional, see Authlogic::Session::MagicColumns)
      t.integer   :login_count,         :null => false, :default => 0
      t.integer   :failed_login_count,  :null => false, :default => 0
      t.datetime  :last_request_at
      t.datetime  :current_login_at
      t.datetime  :last_login_at
      t.string    :current_login_ip
      t.string    :last_login_ip
      t.timestamps
    end

    add_index :users, ["login"], :name => "index_users_on_login", :unique => true
    add_index :users, ["email"], :name => "index_users_on_email", :unique => true
    add_index :users, ["persistence_token"], :name => "index_users_on_persistence_token", :unique => true

  end

  def self.down
    drop_table :users
  end
end

My migration file for add rolename to user is:---

class AddRoleNameToUser < ActiveRecord::Migration
  def change
    add_column :users, :role_name, :string, :after => 'email'
  end
end

When you feel the entire world is against you, there is a little voice in the back of your head that keeps saying... "You can do it, I know you can" That is because you can ♥

Re: Rails 3.1.2 db Migration problem Rake aborted!

You see the exact same problems faced by others also.

I checked the links as--

https://github.com/screenconcept/kuhsaft/issues/8

http://benstack.wordpress.com/2012/01/2 … lnilclass/

The solution doesn't resolved my problem either.

When you feel the entire world is against you, there is a little voice in the back of your head that keeps saying... "You can do it, I know you can" That is because you can ♥

Re: Rails 3.1.2 db Migration problem Rake aborted!

My error log when executing rake db:migrate --trace :


** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
** Execute db:migrate
==  Users: migrating =========================================================
==  Users: migrated (0.0000s) ================================================

rake aborted!
An error has occurred, all later migrations canceled:

undefined method `rows' for nil:NilClass
C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/act
ive_support/whiny_nil.rb:48:in `method_missing'
C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/acti
ve_record/connection_adapters/abstract/database_statements.rb:410:in `last_inser
ted_id'
C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/acti
ve_record/connection_adapters/abstract/database_statements.rb:91:in `insert'
C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/acti
ve_record/connection_adapters/abstract/query_cache.rb:14:in `insert'
C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/acti
ve_record/migration.rb:727:in `record_version_state_after_migrating'
C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/acti
ve_record/migration.rb:688:in `block (2 levels) in migrate'
C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/acti
ve_record/migration.rb:744:in `call'
C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/acti
ve_record/migration.rb:744:in `ddl_transaction'
C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/acti
ve_record/migration.rb:686:in `block in migrate'
C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/acti
ve_record/migration.rb:671:in `each'
C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/acti
ve_record/migration.rb:671:in `migrate'
C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/acti
ve_record/migration.rb:549:in `up'
C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/acti
ve_record/migration.rb:530:in `migrate'
C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/acti
ve_record/railties/databases.rake:161:in `block (2 levels) in <top (required)>'
C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.
rb:205:in `call'
C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.
rb:205:in `block in execute'
C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.
rb:200:in `each'
C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.
rb:200:in `execute'
C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.
rb:158:in `block in invoke_with_call_chain'
C:/RailsInstaller/Ruby1.9.2/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.
rb:151:in `invoke_with_call_chain'
C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.
rb:144:in `invoke'
C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/appli
cation.rb:116:in `invoke_task'
C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/appli
cation.rb:94:in `block (2 levels) in top_level'
C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/appli
cation.rb:94:in `each'
C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/appli
cation.rb:94:in `block in top_level'
C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/appli
cation.rb:133:in `standard_exception_handling'
C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/appli
cation.rb:88:in `top_level'
C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/appli
cation.rb:66:in `block in run'
C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/appli
cation.rb:133:in `standard_exception_handling'
C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/appli
cation.rb:63:in `run'
C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in
`<top (required)>'
C:/RailsInstaller/Ruby1.9.2/bin/rake:19:in `load'
C:/RailsInstaller/Ruby1.9.2/bin/rake:19:in `<main>'
Tasks: TOP => db:migrate

When you feel the entire world is against you, there is a little voice in the back of your head that keeps saying... "You can do it, I know you can" That is because you can ♥

Re: Rails 3.1.2 db Migration problem Rake aborted!

Ouch, deployed on Windows,  that's rough.

I'm afraid I'm out of ideas!

Joe got a job, on the day shift, at the Utility Muffin Research Kitchen, arrogantly twisting the sterile canvas snout of a fully charged icing anointment utensil.

Re: Rails 3.1.2 db Migration problem Rake aborted!

There are some serious compatibility issues using Windows Server 2008+ Rails 3.1.3+ Ruby 1.9.2+mysql2+MySql Server 5.1.
I changed from mysql2 to sqlite3 and all works fine.
Thanks!

When you feel the entire world is against you, there is a little voice in the back of your head that keeps saying... "You can do it, I know you can" That is because you can ♥