rake db:migrate返回错误

时间:2015-08-31 16:18:46

标签: ruby ruby-on-rails-3 ruby-on-rails-4 ruby-on-rails-3.2 syntax-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

1 个答案:

答案 0 :(得分:3)

#up方法中,您要向admin_users添加列,但尚未定义该表。

而不是:

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

尝试:

rename_table("users", "admin_users")