Ruby-on-rails rake db:test:prepare 实际上做了什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15169894/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 21:31:31  来源:igfitidea点击:

What does rake db:test:prepare actually do?

ruby-on-railsruby

提问by bengem

I am following the rails tutorial videos and I can't figure out what the db:test:preparecommand actually does. Can someone provide an explanation?

我正在关注 rails 教程视频,但我无法弄清楚该db:test:prepare命令的实际作用。有人可以提供解释吗?

采纳答案by Richard Brown

The rake db:migrate above runs any pending migrations on the development environment and updates db/schema.rb. The rake db:test:load recreates the test database from the current db/schema.rb. On subsequent attempts, it is a good idea to first run db:test:prepare, as it first checks for pending migrations and warns you appropriately.

上面的 rake db:migrate 在开发环境中运行任何挂起的迁移并更新 db/schema.rb。rake db:test:load 从当前的 db/schema.rb 重新创建测试数据库。在随后的尝试中,首先运行 db:test:prepare 是个好主意,因为它首先检查挂起的迁移并适当地警告您。

-- http://guides.rubyonrails.org/testing.html

-- http://guides.rubyonrails.org/testing.html

Basically it handles cloning the database so you don't have to run the migrations against test to update the test database.

基本上它处理克隆数据库,因此您不必针对测试运行迁移来更新测试数据库。

回答by Kevin Bedell

Specifically, rake db:test:preparewill do the following:

具体来说,rake db:test:prepare会做到以下几点:

  • Check for pending migrations and,
  • load the test schema
  • 检查挂起的迁移和,
  • 加载测试模式

That is, it will look your db/schema.rbfile to determine if any migrations that exist in your project that have not been run. Assuming there are no outstanding migrations, it will then empty the database and reload it based on the contents of the db/schema.rbfile.

也就是说,它将查看您的db/schema.rb文件以确定您的项目中是否存在任何尚未运行的迁移。假设没有未完成的迁移,它将清空数据库并根据db/schema.rb文件的内容重新加载它。

回答by Albert Català

rake db:test:prepare is a good solution for PG issues like this.

rake db:test:prepare 是解决此类PG 问题的好方法。

“PG::UndefinedTable: ERROR: relation does not exist” with a correct Rails naming and convention" where I couldn't just execute rake db:migrate RAILS_ENV=production

“PG::UndefinedTable: 错误:关系不存在”,具有正确的 Rails 命名和约定”,我不能直接执行 rake db:migrate RAILS_ENV=production

When, for example you can't create test database for a bug discussed here: "PG undefinedtable error relation users does not exist"

例如,当您无法为此处讨论的错误创建测试数据库时:“PG undefinedtable 错误关系用户不存在”

All arround this error "PG::UndefinedTable: ERROR: relation xxxxx does not exist”

所有围绕此错误“PG::UndefinedTable:错误:关系 xxxxx 不存在”