rake db:migrate总是输出SELECT" schema_migrations"。* FROM" schema_migrations"

时间:2015-03-09 03:12:16

标签: ruby-on-rails postgresql ruby-on-rails-4 rspec

每次运行rake db:migrate时,我都会得到以下输出:

  ActiveRecord::SchemaMigration Load (0.9ms)  SELECT "schema_migrations".* FROM "schema_migrations"
  ActiveRecord::SchemaMigration Load (0.2ms)  SELECT "schema_migrations".* FROM "schema_migrations"

这是在安装rspec-rails gem。

之后开始的

当我尝试运行测试时,我得到以下输出:

  ActiveRecord::SchemaMigration Load (0.4ms)  SELECT "schema_migrations".* FROM "schema_migrations"
   (0.2ms)  BEGIN
Processing by WelcomeController#index as HTML
  Rendered welcome/index.html.erb within layouts/application (0.3ms)
Completed 200 OK in 17ms (Views: 8.3ms | ActiveRecord: 3.1ms)
   (0.2ms)  ROLLBACK
.   (0.1ms)  BEGIN
Processing by WelcomeController#index as HTML
Completed 200 OK in 1ms (Views: 1.0ms | ActiveRecord: 0.0ms)
   (0.1ms)  ROLLBACK
.

Finished in 0.03 seconds (files took 1.5 seconds to load)
2 examples, 0 failures

我创建了test_database并运行了迁移。是什么原因造成了这个错误?

2 个答案:

答案 0 :(得分:2)

tl; dr这不是错误

schema_migrations是rails存储其为当前环境的数据库运行的所有迁移的VERSION数的表。

在迁移数据库时(它也会在规范之前执行),它将始终检查这一点,以查看是否有任何尚未为此数据库运行的挂起迁移。

答案 1 :(得分:2)

Rspec-rails生成了这个:它是在运行任何测试之前自动运行任何挂起的迁移的检查。它位于您的/spec/rails_helpers.rb文件中并说:

# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.maintain_test_schema!

将数据保留在那里是一个非常好的主意,这样当您的数据库处于良好/完整/预期状态时,您就不会无意中运行测试(如果您有迁移,可能会发生这种情况)你已经忘了跑了。

相关问题