![](/img/trans.png)
[英]Rails Tutorial: SQLite3::ConstraintException: UNIQUE constraint failed: users.email
[英]Rails - All tests fail - ' … ConstraintException: UNIQUE constraint failed: admins.email … '
當我運行this: rails test
,所有我的(10)測試都失敗了,並且出現了相同的錯誤(唯一約束失敗)。 這是錯誤消息:
E
Error:
WelcomeControllerTest#test_the_truth:
ActiveRecord::RecordNotUnique: SQLite3::ConstraintException: UNIQUE
constraint failed: admins.email: INSERT INTO "admins" ("created_at",
"updated_at", "id") VALUES ('2017-02-20 16:22:33.516784', '2017-02-20
16:22:33.516784', 298486374)
bin/rails test test/controllers/welcome_controller_test.rb:4
其中一項測試是:
test "the truth" do
assert true
end
通過瀏覽,我發現可能與固定裝置有關。 在/test/fixtures/admin.yml中,那里是:
# This model initially had no columns defined. If you
# add columns to the model remove the '{}' from the fixture
# names and add the columns immediately below each fixture,
# per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
如果然后我注釋掉one: {}
和two: {}
,那么它將起作用。 我不知道為什么會這樣? 有人可以解釋嗎?
它不喜歡您使用兩個為零的電子郵件,而是期望每個模型具有唯一的電子郵件地址。 更改為此:
# This model initially had no columns defined. If you
# add columns to the model remove the '{}' from the fixture
# names and add the columns immediately below each fixture,
# per the syntax in the comments below
#
one:
email: 'one@one.com'
two:
email: 'two@two.com'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.