Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rake db:migrate VERSION=0 table does not exist

I am following Lynda ruby on rails tutorial. I have already ran the code "rake db:migrate" after several unsuccessful attempts. I was then told to run "rake db:migrate VERSION=0". This gives me errors once again, this time I can't fix it. I have tried last night and this morning to no avail.

Remember when answering I am new to coding, so please explain in a way a newbie could understand.

lexi87$ rake db:migrate VERSION=0
==  AlterUsers: reverting =====================================================
-- remove_index("admin_users", "username")
rake aborted!
An error has occurred, all later migrations canceled:

Index name 'index_admin_users_on_username' on table 'admin_users' does not exist
/Users/lexi87/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/schema_statements.rb:587:in `index_name_for_remove'
/Users/lexi87/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/schema_statements.rb:366:in `remove_index'
/Users/lexi87/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/migration.rb:466:in `block in method_missing'
/Users/lexi87/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/migration.rb:438:in `block in say_with_time'
/Users/lexi87/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/migration.rb:438:in `say_with_time'
/Users/lexi87/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/migration.rb:458:in `method_missing'
/Users/lexi87/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/migration.rb:334:in `method_missing'
/Users/lexi87/Sites/simple_cms/db/migrate/20130108015542_alter_users.rb:14:in `down'
/Users/lexi87/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/migration.rb:376:in `down'
/Users/lexi87/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/migration.rb:410:in `block (2 levels) in migrate'
/Users/lexi87/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/migration.rb:410:in `block in migrate'
/Users/lexi87/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:129:in `with_connection'
/Users/lexi87/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/migration.rb:389:in `migrate'
/Users/lexi87/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/migration.rb:528:in `migrate'
/Users/lexi87/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/migration.rb:720:in `block (2 levels) in migrate'
/Users/lexi87/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/migration.rb:777:in `call'
/Users/lexi87/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/migration.rb:777:in `ddl_transaction'
/Users/lexi87/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/migration.rb:719:in `block in migrate'
/Users/lexi87/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/migration.rb:700:in `each'
/Users/lexi87/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/migration.rb:700:in `migrate'
/Users/lexi87/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/migration.rb:574:in `down'
/Users/lexi87/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/migration.rb:555:in `migrate'
/Users/lexi87/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/railties/databases.rake:179:in `block (2 levels) in <top (required)>'
/Users/lexi87/.rvm/gems/ruby-1.9.2-p320/bin/ruby_noexec_wrapper:14:in `eval'
/Users/lexi87/.rvm/gems/ruby-1.9.2-p320/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

And here is the rb file.

class AlterUsers < ActiveRecord::Migration

  def self.up
    rename_table("users", "admin_users")
    add_column("admin_users", "username", :string, :limit => 25)
    change_column("admin_users", "email", :string, :limit => 100)
    rename_column("admin_users", "password", "hashed_password")
    add_column("admin_users", "salt", :string, :limit => 40)
    puts "*** About to add an index ***"
    add_index("admin_users", "username")
  end

  def self.down
       remove_index("admin_users", "username")
       remove_column("admin_users", "salt")
       remove_column("admin_users", "hashed_password", "password")
       remove_column("admin_users", "email", :string, :default => "", :null => false)
       remove_column("admin_users", "username")
       rename_table("admin_users", "users")
  end

end
like image 266
Cornelius Wilson Avatar asked Jan 08 '13 14:01

Cornelius Wilson


2 Answers

rake db:migrate VERSION=0 rollback all migration

error clearly said

Index name 'index_admin_users_on_username' on table 'admin_users' does not exist

I suspect you actually trying to rollback migration that never was applied so that the index does not exist. Or you are make changes in migration after you already applied it. My suggestion will be drops the database, create and apply all migration again.

rake db:drop
rake db:create
rake db:migrate
like image 61
Eugene Rourke Avatar answered Nov 11 '22 21:11

Eugene Rourke


You are removing the index which doesn't exist. Always use the following order:

1) rake db:create

2) rake db:migrate

Also in context of the error you are getting, remember rake db:migrate VERSION=0 will remove all migrations, if that's what you're trying to do and since the indexing wasn't there before so it will through an error..

I also suspect that your database.yml file that contains setting for the mysql is having wrong credentials, especially the setting for username and password. Check and correct it and then do migrations.

like image 1
My God Avatar answered Nov 11 '22 21:11

My God