- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我对 Rails 完全陌生,我几乎不知道自己在做什么。但。问题是:使用 Devise 注册新用户会导致:
SQLite3::ConstraintException: column email is not unique:
INSERT INTO "users" ("created_at","encrypted_password", "name", "updated_at")
VALUES (?, ?, ?, ?)
以及请求参数:
{"utf8"=>"✓",
"authenticity_token"=>"1bgk4ovS3JitphVkIvcCZi3ex8QsBq4eEf6ZihQLiHg=",
"user"=>{"name"=>"Someone",
"email"=>"8@prosto.me",
"password"=>"[FILTERED]"},
"commit"=>"Sign up"}
用户模型:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable;
end
数据库迁移:
class DeviseCreateUsers < ActiveRecord::Migration
def self.up
change_table(:users) do |t|
## Database authenticatable
t.string :email, :null => false, :default => ""
t.string :name, :null => false, :default => ""
t.string :encrypted_password, :null => false, :default => ""
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, :default => 0
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
t.string :last_sign_in_ip
## Confirmable
# t.string :confirmation_token
# t.datetime :confirmed_at
# t.datetime :confirmation_sent_at
# t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
# t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
# t.string :unlock_token # Only if unlock strategy is :email or :both
# t.datetime :locked_at
## Token authenticatable
# t.string :authentication_token
# Uncomment below if timestamps were not included in your original model.
# t.timestamps
end
add_index :users, :email, :unique => true
add_index :users, :name, :unique => true
add_index :users, :reset_password_token, :unique => true
# add_index :users, :confirmation_token, :unique => true
# add_index :users, :unlock_token, :unique => true
# add_index :users, :authentication_token, :unique => true
end
def self.down
# By default, we don't want to make any assumption about how to roll back a migration when your
# model already existed. Please edit below which fields you would like to remove in this migration.
end
end
请告诉我是否需要提供任何其他代码。并感谢您提前提供的所有帮助。
更新数据库架构:
ActiveRecord::Schema.define(version: 20131012114812) do
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 "name"
end
add_index "users", ["email"], name: "index_users_on_email", unique: true
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
更新 2:认证也有问题。 Devise 会为之前成功注册的任何尝试登录的用户提示“电子邮件或密码无效”。
最佳答案
SQLite 告诉您它正在尝试创建一个新记录,其中一个值将是一封电子邮件,但该电子邮件已经存在一条记录。
读取数据库记录的一种简单方法是在终端窗口中查询数据库:
$ rails console
$ User.all
如果您想查看您的测试数据库,它将与您的设备一起加载:
$ rails console -e=test
$ User.all
查找与您尝试创建的记录具有相同电子邮件地址的记录。
如果这是您第一次使用 Devise,您应该检查一下您的装置。 Devise 目前默认为两个没有属性的灯具。如果您在测试环境中运行,那么这些固定装置将作为两条记录加载到测试数据库中,电子邮件为零值,这是重复的电子邮件值。像下面这样的固定装置会让您传递错误消息。
file: app/test/fixtures/users.yml
one:
email: user@example.com
encrypted_password: password1
two:
email: user2@example.com
encrypted_password: password2
关于ruby-on-rails - SQLite3::ConstraintException:列电子邮件不是唯一的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19364622/
我有一个独立的应用程序,它在将平面文件导入 SQL 数据库之前对其进行数据检查。 在这样的上下文中,抛出 System.Data.ConstraintException 是否有意义? (这个例子是人为
我有一个独立的应用程序,它在将平面文件导入 SQL 数据库之前对其进行数据检查。 在这样的上下文中,抛出 System.Data.ConstraintException 是否有意义? (这个例子是人为
我对 Rails 完全陌生,我几乎不知道自己在做什么。但。问题是:使用 Devise 注册新用户会导致: SQLite3::ConstraintException: column email is n
我正在尝试学习 Ruby on Rails,但遇到了一个需要帮助的问题。我想做的是创建一个带有表单的“项目经理”,但是当我填写表单并点击提交时,会显示以下错误: ActiveRecord::State
我在更新/创建 CoverImage 对象时使用 saveOrUpdate()。偶尔我会在主键上遇到约束冲突。 org.hibernate.exception.ConstraintViolationE
我正在使用 C#/Mono 访问 Sqlite 数据库。 以下查询在任何数据库应用程序中都能正常工作,但当我尝试加载结果时 DataTable 一直提示。 这是一个片段 cmd.Command
我正在使用 DevExpress GridControl 创建一个表单,使用户能够输入一些数据。网格绑定(bind)到 DataTable,其中一列定义为唯一的数据源。 DataTable dtDet
我有两个表 orders 和 orderdetails 表订单(PK = id,orderno 上的 UNIQUE 索引) |id|orderno| | 1|1000 | | 2|1001 |
我希望有人能够帮助解决我的 SQLite 数据库问题。 在使用 C# 查询我的 SQLite 数据库时,我收到了 ConstraintException。完整的异常消息是“无法启用约束。一行或多行包含
我有一个创建艺术家并将其与用户关联的 resque 工作。用户 has_and_belongs_to_many :艺术家,艺术家 has_and_belongs_to_many :用户。 def se
我觉得我遗漏了一些非常明显的东西,但我正在做的是测试 destroy在我的用户模型上路由。 当我尝试和 @user.destroy ,我得到以下异常: *** ActiveRecord::Invali
给定以下 ASP.NET MVC Controller 代码: [HttpPost] public ActionResult Create(FormCollection collect
我正在关注 Rails 教程。我在 ch。 6,我在使用 SQLite3 时遇到一个奇怪的错误(为了记录,我使用的是 sqlite 版本 1.3.10,而教程使用的是 1.3.9) 我在运行 rake
在我的模型中,项目拥有并属于许多用户,因此他们有一个连接表 projects_users。当我插入线 @project.members += User.find params[:member_ids]
我正在将 Devise 和 Paperclip 与 Rails 4 应用程序一起使用。 我正在尝试找出无法为同一用户添加另一个 pin 的原因。据我从错误中了解到,它具有用户独特性。我对吗?如何修复它
当我运行 rake db:seed 时,有些东西坏了! 我收到以下错误: ray@ray-virtual-machine:~/ticketee$ rake db:seed rake aborted!
我刚刚安装了 devise gem,但出现以下错误: Error: AccountsControllerTest#test_should_update_account: ActiveRecord::R
我正在使用Sqlite开发Rails应用程序,并且有一个与其他几个表关联的用户表。尝试在Users中重命名列时,运行rails db:migrate时出现主题错误。 我在这里看到很多类似问题的帖子,但
我正在尝试对我的应用程序运行单元测试,我最初的错误是“表 xx 没有名为 yy 的列”,因此在我的 yml 文件中我将字段更改为 id。但是,现在它给了我这个错误: CarsControllerTes
我是 Ruby on Rails 的新手。我尝试制作标签并可以选择删除标签。当我想销毁标签时,我收到此错误 SQLite3::ConstraintException: FOREIGN KEY cons
我是一名优秀的程序员,十分优秀!