rajat_474 rajat_474 - 1 month ago 10
Ruby Question

Getting build task error while running rake db:migrate in rails 3

I am getting the following error while running command

rake db:migrate VERSION=201504******.


Error:


rake aborted!

Don't know how to build task '20150419131135'


Actually i have a migration file already.Now i am connecting to a new database .Here i want to create table in that DB.Please check my below file.

20150419131135_create_users.rb:

class CreateUsers < ActiveRecord::Migration
def self.up
if !table_exists? :users
create_table :users do |t|
t.string :contact_name
t.string :login_id
t.string :password_hash
t.string :password_salt
t.string :phone
t.string :address
t.timestamps
end
end
end
end


class CreateUsers < ActiveRecord::Migration
def self.down
drop_table :users if !table_exists?(:users)
end
end


After migrate this I got the above error.Please help me to resolve this error.

Answer

self.down and self.up methods should be within one CreateUsers class:

class CreateUsers < ActiveRecord::Migration
  def self.up
      create_table :users do |t|
        t.string :contact_name
        t.string :login_id
        t.string :password_hash
        t.string :password_salt
        t.string :phone
        t.string :address
        t.timestamps
      end unless table_exists? :users
    end
  end

  def self.down
    drop_table :users if table_exists? :users
  end
end