gpt4 book ai didi

ruby-on-rails - Rails:使用 ActiveRecord::StatementInvalid: PG::NotNullViolation: ERROR 测试失败

转载 作者:太空宇宙 更新时间:2023-11-03 17:47:24 24 4
gpt4 key购买 nike

我有一个非常简单的用户模型并想测试它:

class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name
t.string :email

t.timestamps null: false
end
end
end

这是我在 test/models/user_test.rb 中的内容:

require 'test_helper'

class UserTest < ActiveSupport::TestCase

test "shoudl always pass" do
assert true
end

end

命令 rake test 抛出以下错误:

  1) Error:
UserTest#test_shoudl_always_pass:
ActiveRecord::StatementInvalid: PG::NotNullViolation: ERROR: null value in column "name" violates not-null constraint
DETAIL: Failing row contains (980190962, null, null, null, 2015-10-12 09:10:40, 2015-10-12 09:10:40).
: INSERT INTO "keywords" ("created_at", "updated_at", "id") VALUES ('2015-10-12 09:10:40', '2015-10-12 09:10:40', 980190962)

为什么我在一个几乎为空的测试用例上遇到如此奇怪的错误以及如何解决它?

最佳答案

解决了!注释行 fixtures :all in test_helper.rb

关于ruby-on-rails - Rails:使用 ActiveRecord::StatementInvalid: PG::NotNullViolation: ERROR 测试失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33077366/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com