Reputation: 2914
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
Upvotes: 5
Views: 7899
Reputation: 3042
Guess 1. You cannot jump back to other VERSTION (it always shows error on Terminal). 2. You also cannot 'rake db:rollback' 3. You cannot 'rake db:migrate down' as well. 4. You are using MySQL.
Take a deep breath, try doing this instead.
A. Open Terminal application, and type this.
rake db:drop
After that, try looking in your database. There must have no "your database".
B. Re-create database (Use MySQL command directly or follow up on Rake command) for MySQL
CREATE DATABASE database_name;
for Rake
rake db:create
as Mr. Eugene answered above.
C. Make migration, go to Terminal and type this.
rake db:migrate
After that you should login to your database to check any activities on its.
Upvotes: 0
Reputation: 23344
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.
Upvotes: 1
Reputation: 4934
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
Upvotes: 4