每次运行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并运行了迁移。你知道是什么导致了这个错误吗?
发布于 2015-03-09 11:24:41
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!保留这一行是一个非常好的主意,这样您就不会在数据库未处于良好/完成/预期状态时无意中运行测试(如果有迁移挂起而忘记运行,就会发生这种情况)。
发布于 2015-03-09 11:19:39
tl;dr这不是一个错误
schema_migrations是一个表,rails在其中存储它为当前环境的数据库运行的所有迁移的版本号。
在迁移数据库时,它将始终检查这一点(它在规范之前也是这样做的),以查看是否有任何尚未为该数据库运行的挂起迁移。
https://stackoverflow.com/questions/28934724
复制相似问题