rake db:migrate returns 有错误

rake db:migrate returns with error

我 运行 rake db:migrate 并且我在终端中遇到了这个错误

SQLite3::SQLException: no such table: admin_users: ALTER TABLE "admin_users" ADD "username" varchar(25)/Users/IsaiahxD/.rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:91:in `initialize'
/Users/IsaiahxD/.rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:91:in `new'
/Users/IsaiahxD/.rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:91:in `prepare'
/Users/IsaiahxD/.rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:134:in `execute'
/Users/IsaiahxD/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.3/lib/active_record/connection_adapters/sqlite3_adapter.rb:329:in `block in execute'
/Users/IsaiahxD/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract_adapter.rb:473:in `block in log'

我查看了我的 alter_user.rb 文件 class AlterUsers < ActiveRecord::Migration

这是文件20150825065823_alter_users.rb

def up
  rename_table("users", "admin_users.broken")
  add_column("admin_users", "username", :string, :limit => 25, :after => "email" )
  change_column("admin_users", "email", :string, :limit => 100)
  rename_column("admin_users", "broken", "hashed_password")
  puts "*** Adding an index is next ***"
  add_index("admin_users", "username")
end

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

在您的 #up 方法中,您正在向 admin_users 添加列,但您尚未定义 table。

而不是:

rename_table("users", "admin_users.broken")

尝试:

rename_table("users", "admin_users")