Rails PostgreSQL:列“table_rows”不存在(ActiveRecord :: StatementInvalid)

时间:2015-01-13 08:20:00

标签: ruby-on-rails ruby postgresql activerecord

突然间,我在运行测试时遇到了这个奇怪的错误。 rails 4.1.5 pg 0.18.1

尝试删除并重新创建数据库,但没有任何帮助。发展似乎有效,而不是测试。

RAILS_ENV=test rake db:create db:migrate

请告知。

...gems/activerecord-4.1.5/lib/active_record/connection_adapters/postgresql/
database_statements.rb:128:in `async_exec':
PG::UndefinedColumn: ERROR:  
column "table_rows" does not exist (ActiveRecord::StatementInvalid)
LINE 1: ...chema.tables WHERE table_schema = 'real_test' AND table_rows...
                                                             ^
: SELECT table_name FROM information_schema.tables WHERE table_schema = 'real_test' AND table_rows > 0
from ...ruby/gems/2.2.0/gems/activerecord-4.1.5/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `block in execute'
from ...ruby/gems/2.2.0/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract_adapter.rb:373:in `block in log'
from ...ruby/gems/2.2.0/gems/activesupport-4.1.5/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
...

完全回溯:

$ rspec
Run options: include {:focus=>true}

All examples were filtered out; ignoring {:focus=>true}

Randomized with seed 14295

Finished in 0.09195 seconds (files took 4.81 seconds to load)
0 examples, 0 failures

Randomized with seed 14295

/Users/pain/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-4.1.5/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `async_exec': PG::UndefinedColumn: ERROR:  column "table_rows" does not exist (ActiveRecord::StatementInvalid)
LINE 1: ...chema.tables WHERE table_schema = 'real_test' AND table_rows...
                                                             ^
: SELECT table_name FROM information_schema.tables WHERE table_schema = 'real_test' AND table_rows > 0
        from /Users/pain/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-4.1.5/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `block in execute'
        from /Users/pain/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract_adapter.rb:373:in `block in log'
        from /Users/pain/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/activesupport-4.1.5/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
        from /Users/pain/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract_adapter.rb:367:in `log'
        from /Users/pain/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-4.1.5/lib/active_record/connection_adapters/postgresql/database_statements.rb:127:in `execute'
        from /Users/pain/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/database_cleaner-1.4.0/lib/database_cleaner/active_record/deletion.rb:57:in `tables_with_new_rows'
        from /Users/pain/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/database_cleaner-1.4.0/lib/database_cleaner/active_record/deletion.rb:49:in `tables_to_truncate'
        from /Users/pain/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/database_cleaner-1.4.0/lib/database_cleaner/active_record/deletion.rb:80:in `block in clean'
        from /Users/pain/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-4.1.5/lib/active_record/connection_adapters/postgresql/referential_integrity.rb:17:in `disable_referential_integrity'
        from /Users/pain/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/database_cleaner-1.4.0/lib/database_cleaner/active_record/deletion.rb:79:in `clean'
        from /Users/pain/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/database_cleaner-1.4.0/lib/database_cleaner/base.rb:40:in `clean_with'
        from /Users/pain/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/database_cleaner-1.4.0/lib/database_cleaner/configuration.rb:91:in `block in clean_with'
        from /Users/pain/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/database_cleaner-1.4.0/lib/database_cleaner/configuration.rb:91:in `each'
        from /Users/pain/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/database_cleaner-1.4.0/lib/database_cleaner/configuration.rb:91:in `clean_with'
        from /Users/pain/Sites/real/spec/features/acceptance_helper.rb:40:in `block (2 levels) in <top (required)>'
        from /Users/pain/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/rspec-core-c22e9023dacb/lib/rspec/core/example.rb:331:in `instance_exec'
        from /Users/pain/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/rspec-core-c22e9023dacb/lib/rspec/core/example.rb:331:in `instance_exec'
        from /Users/pain/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/rspec-core-c22e9023dacb/lib/rspec/core/hooks.rb:350:in `run'
        from /Users/pain/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/rspec-core-c22e9023dacb/lib/rspec/core/configuration.rb:1525:in `block in run_hooks_with'
        from /Users/pain/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/rspec-core-c22e9023dacb/lib/rspec/core/configuration.rb:1525:in `each'
        from /Users/pain/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/rspec-core-c22e9023dacb/lib/rspec/core/configuration.rb:1525:in `run_hooks_with'
        from /Users/pain/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/rspec-core-c22e9023dacb/lib/rspec/core/configuration.rb:1499:in `with_suite_hooks'
        from /Users/pain/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/rspec-core-c22e9023dacb/lib/rspec/core/runner.rb:109:in `block in run_specs'
        from /Users/pain/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/rspec-core-c22e9023dacb/lib/rspec/core/reporter.rb:62:in `report'
        from /Users/pain/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/rspec-core-c22e9023dacb/lib/rspec/core/runner.rb:108:in `run_specs'
        from /Users/pain/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/rspec-core-c22e9023dacb/lib/rspec/core/runner.rb:86:in `run'
        from /Users/pain/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/rspec-core-c22e9023dacb/lib/rspec/core/runner.rb:70:in `run'
        from /Users/pain/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/rspec-core-c22e9023dacb/lib/rspec/core/runner.rb:38:in `invoke'
        from /Users/pain/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/rspec-core-c22e9023dacb/exe/rspec:4:in `<top (required)>'
        from ./bin/rspec:16:in `load'
        from ./bin/rspec:16:in `<main>'

1 个答案:

答案 0 :(得分:4)

database_cleaner升级到1.3.0后,似乎问题出现在1.4.0。评论下面的测试至少开始工作:

   39   config.before(:suite) do
~  40     # DatabaseCleaner.clean_with(:deletion)
   41   end

仅供记录。 database_cleaner 1.4.0