新手问题 按照 Ruby on Rails tutorials 上的方式谢了一个 test,但是出了一个 error

ThanksSirAlec · December 06, 2017 · Last by aelaa replied at December 06, 2017 · 2244 hits
Error:
SessionsControllerTest#test_should_get_new:
ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR:  column "increment_by" does not exist
LINE 1: ...oups_id_seq"', (SELECT COALESCE(MAX("id")+(SELECT increment_...
                                                             ^
:               SELECT setval('"public"."chat_groups_id_seq"', (SELECT COALESCE(MAX("id")+(SELECT increment_by FROM "public"."chat_groups_id_seq"), (SELECT min_value FROM "public"."chat_groups_id_seq")) FROM "chat_groups"), false)

不太理解的是我写的 test 是一个 get url 的 test,为什么会报一个关于数据库的 error,而且我都没定义过 increment_by,当然不会存在这一列,这个 error 是怎么来的。

test 如下

test "should get new" do
    get sessions_new_url
    assert_response :success
  end

Haven't you updated PostgreSQL from 9 to 10? I had same error, because PostgreSQL 10 has another format of sequences.

Reply to aelaa

蒂花之秀

我猜是你的 migration 没跑吗?而且你这个 get 会调用代码,所以会产生数据库调用,然后出错,这个是可能发生的

Reply to hiveer

程序都可以运行了,只是有个疑问,因为我不管写什么测试都会报这个错,那写测试不就没有用了吗

Reply to aelaa

I use PostgreSQL 10 from the beginning

and what version of Rails? PostgreSQL 10 supports since 5.2.0 beta

Reply to aelaa

maybe that's the point. my rails version is 5.0.3

Try to update, it should works well on 5.2+

You need to Sign in before reply, if you don't have an account, please Sign up first.