gpt4 book ai didi

ruby-on-rails - rake 分贝 :migrate VERSION=0 table does not exist

转载 作者:行者123 更新时间:2023-12-03 16:03:51 26 4
gpt4 key购买 nike

我正在关注 Lynda ruby​​ on rails 教程。在几次不成功的尝试之后,我已经运行了代码“rake db:migrate”。然后我被告知运行“rake db:migrate VERSION=0”。这再次给了我错误,这次我无法修复它。我昨晚和今天早上都试过了,没有用。

请记住,在回答我是编码新手时,请以新手可以理解的方式进行解释。

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)

这是 rb 文件。
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

最佳答案

rake 分贝:迁移版本=0 回滚所有迁移

错误说清楚

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

我怀疑您实际上试图回滚从未应用过的迁移,以便索引不存在。
或者您在应用迁移后进行更改。
我的建议是
删除数据库,再次创建并应用所有迁移。
rake db:drop
rake db:create
rake db:migrate

关于ruby-on-rails - rake 分贝 :migrate VERSION=0 table does not exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14216698/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com