[英]Ruby on Rails: SQLite3::SQLException: no such column:
[英]SQLite3::SQLException: no such table for Rails app
我在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:migrate
或db: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>]>
看來您尚未在測試環境中創建數據庫。 跑:
rake db:create RAILS_ENV=test
rake db:migrate RAILS_ENV=test
那應該解決它
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.