【问题标题】:SQLite3::SQLException: no such table for Rails appSQLite3::SQLException:Rails 应用程序没有这样的表
【发布时间】:2014-11-21 07:41:24
【问题描述】:

我在注册我的 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>]> 

【问题讨论】:

  • rails console -e=test 打开你的测试控制台而不是开发控制台,所以试试rails console 然后在那里查看数据库
  • 你在同一个目录下工作吗?因为这是一个常见的错误。
  • 在运行任何其他命令之前,您是否运行过:RAILS_ENV=test rake db:create db:migrate
  • 我做了 db:migrate RAILS_ENV=development,也试过没有 rails_env 位。

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


【解决方案1】:

您似乎还没有在测试环境中创建数据库。运行:

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

希望能解决它

【讨论】:

    猜你喜欢
    • 2021-04-10
    • 2020-10-18
    • 1970-01-01
    • 1970-01-01
    • 2018-08-18
    • 2022-01-21
    • 2021-07-24
    • 2017-09-12
    • 2017-12-10
    相关资源
    最近更新 更多