SQLite3 :: SQLException:没有这样的Rails应用程序表

时间:2014-09-26 10:09:51

标签: sql ruby-on-rails ruby ruby-on-rails-4 sqlite

我在使用我的rails应用程序注册时遇到了一些问题,出现了错误     "列电子邮件不是唯一的"
尽管我知道我之前没有使用过这个特定的电子邮件地址。我以为我无论如何都要检查我的数据库,然后运行:

rails console -e=test

查看Users.all以查看已保存的记录。但是,不仅没有保存,而且我收到错误:

**SQLite3::SQLException: no such table: users: SELECT "users".* FROM "users"
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: users: SELECT "users".* FROM "users"**  

但在我的架构中,它清楚地说

  create_table "users", force: true do |t|
    t.string   "email",                  default: "", null: false
    t.string   "encrypted_password",     default: "", null: false
    t.string   "reset_password_token"
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.integer  "sign_in_count",          default: 0,  null: false
    t.datetime "current_sign_in_at"
    t.datetime "last_sign_in_at"
    t.string   "current_sign_in_ip"
    t.string   "last_sign_in_ip"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.string   "provider"
    t.string   "uid"
  end

如果我继续尝试db:migratedb:migrate RAILS_ENV=development,则没有任何反应 有什么建议吗?

修改:运行 rails console (不是-e = test)会产生以下结果:

#<ActiveRecord::Relation [#<User id: 1, email: "", encrypted_password: "", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, created_at: "2014-09-22 14:03:39", updated_at: "2014-09-22 14:03:39", provider: nil, uid: nil>]> 

1 个答案:

答案 0 :(得分:2)

看起来您还没有在测试环境中创建数据库。运行:

rake db:create RAILS_ENV=test 
rake db:migrate RAILS_ENV=test 

应该有希望解决它