rails上的ruby(5) - SQLite3 :: SQLException:没有这样的表

时间:2017-12-06 15:40:39

标签: ruby-on-rails sqlite sqlexception

我在SQLite数据库中创建了另一个表,但遗憾的是无法通过rails控制台访问它。我通过GUI(SQL浏览器的SQL浏览器)添加了一行数据,现在我试图通过它访问它,但它给了我错误 " ActiveRecord :: StatementInvalid:SQLite3 :: SQLException:没有这样的表:"

在我的架构中,我已经可以看到它了:

create_table "user_information", force: :cascade do |t|
t.string "charity_name", limit: 100
t.string "res_exp_contact_name", limit: 50
t.string "res_exp_contact_email", limit: 100, default: "", null: false
t.string "grants_contact_name", limit: 50
t.string "grants_contact_email", limit: 100, default: "", null: false
t.boolean "submission_status_res_exp"
t.integer "submission_status_grants"
t.string "category"
t.string "username"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "password_digest"
t.index ["username"], name: "index_user_information_on_username"
end

这就是终端的样子:

ck$ rails console
Running via Spring preloader in process 8442
Loading development environment (Rails 5.1.4)
Cannot read termcap database;
using dumb terminal settings.
irb(main):001:0> user = UserInformation.first
   UserInformation Load (0.2ms)  SELECT  "user_informations".* FROM 
   "user_informations" ORDER BY "user_informations"."id" ASC LIMIT ?  
[["LIMIT", 1]]
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: 
user_informations: SELECT  "user_informations".* FROM 
"user_informations" ORDER BY "user_informations"."id" ASC LIMIT ?
    from (irb):1

有谁知道这个解决方案?我很感激任何提示! : - )

1 个答案:

答案 0 :(得分:3)

解决了它。答案是你总是将表命名为复数,所以我添加了一个从" user_information"重命名我的表的迁移。 to" user_informations"。现在它有效!