【发布时间】: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: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>]>
【问题讨论】:
-
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