在我最近的一个迁移文件中,我删除了很久以前创建的表(drop_table:transactions)
此后“rake test”失败并带有
ActiveRecord::StatementInvalid: PG::Error: ERROR: relation "transactions" does not exist
LINE 1: DELETE FROM "transactions"
^
: DELETE FROM "transactions"
C:/Ruby/1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:1161:in `async_exec'
C:/Ruby/1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:1161:in `exec_no_cache'
C:/Ruby/1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:671:in `block in exec_delete'
C:/Ruby/1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
C:/Ruby/1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
C:/Ruby/1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
C:/Ruby/1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:670:in `exec_delete'
C:/Ruby/1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/database_statements.rb:101:in `delete'
C:/Ruby/1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/query_cache.rb:14:in `delete'
C:/Ruby/1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/fixtures.rb:497:in `block (4 levels) in create_fixtures'
C:/Ruby/1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/fixtures.rb:496:in `each'
C:/Ruby/1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/fixtures.rb:496:in `block (3 levels) in create_fixtures'
C:/Ruby/1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/fixtures.rb:492:in `each'
C:/Ruby/1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/fixtures.rb:492:in `block (2 levels) in create_fixtures'
C:/Ruby/1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
C:/Ruby/1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/fixtures.rb:491:in `block in create_fixtures'
C:/Ruby/1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:523:in `disable_referential_integrity'
C:/Ruby/1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/fixtures.rb:476:in `create_fixtures'
C:/Ruby/1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/fixtures.rb:895:in `load_fixtures'
C:/Ruby/1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/fixtures.rb:849:in `setup_fixtures'
C:/Ruby/1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:407:in `_run__291023375__setup__979454852__callbacks'
C:/Ruby/1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:405:in `__run_callback'
C:/Ruby/1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:385:in `_run_setup_callbacks'
C:/Ruby/1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:81:in `run_callbacks'
C:/Ruby/1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/testing/setup_and_teardown.rb:35:in `run'
我没有在整个应用程序中提及交易(在迁移文件旁边)。
它在开发和生产环境中运行良好,只是测试失败了。
我试过rake db:test:prepare但是它已经在rake测试后运行了。我在运行rake测试之前删除了测试数据库,重新创建了数据库,但发生了同样的错误。
知道在哪里查看/如何修复它以便我可以再次运行我的测试?
答案 0 :(得分:1)
stacktrace正在调用fixtures
创建方法。
请检查所有灯具,检查是否与transation
型号无关。用grep,就可以了
答案 1 :(得分:0)
首先验证所有三个db(transactions
)中都不存在dev,pro,test
表
如果已经完成,则需要rake db:migrate
运行更新您的schema.rb
.i相信transactions
表仍然存在于schema.rb
中,也需要更新。