我在SQLite数据库中创建了另一个表,但不幸的是无法通过rails控制台访问它。我通过GUI(SQLite的数据库浏览器)添加了一行数据,现在正尝试通过它访问它,但它给了我错误
“ 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
有人知道解决方案吗?我感谢任何提示! :-)
最佳答案
解决了。答案是,您总是以多种形式命名表,因此我添加了一个迁移,该迁移将表从“ user_information”重命名为“ user_informations”。现在可以了!