简体   繁体   English

为什么Rails要求我一次又一次运行rake db:migrate RAILS_ENV = test?

[英]Why Rails ask me to run rake db:migrate RAILS_ENV=test again and again?

Could you help me with this issue: 您能帮我解决这个问题吗:

When executing 执行时

root@myproject-dev:~/projects/myproject-dev$ rake db:migrate:status

database: myproject-db

 Status   Migration ID    Migration Name
--------------------------------------------------
   (...)
   up     20151104094107  Add need to something
   up     20151111082356  ********** NO FILE **********
   up     20151113024714  Add approved something
   up     20151116075224  Add something
   up     20151130041605  Change column name

root@myproject-dev:~/projects/myproject-dev$ bundle exec rspec

RSpec is shutting down and will print the summary report... Interrupt again to force quit.
/home/xxx/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/migration.rb:389:in `check_pending!':  (ActiveRecord::PendingMigrationError)

Migrations are pending. To resolve this issue, run:

        bin/rake db:migrate RAILS_ENV=test

Status show me everything is up and the rake db:migrate RAILS_ENV=test has already been performed correctly. 状态显示一切正常,并且耙db:migrate RAILS_ENV = test已经正确执行。 If I execute it again I get errors (of course). 如果我再次执行它,我会得到错误(当然)。

Why Rails ask me to run rake db:migrate RAILS_ENV=test again and again ? 为什么Rails要求我一次又一次运行rake db:migrate RAILS_ENV = test?

There are 3+ default Rails environments: 有3种以上的默认Rails环境:

  • development 发展
  • production 生产
  • test 测试

Each of them is supposed to have different settings, including different database to operate on. 他们每个人应该具有不同的设置,包括要操作的不同数据库。 This is done to separate environments and prevent accidental data corruption/damage when running in inappropriate environment. 这样做是为了隔离环境,并防止在不合适的环境中运行时意外的数据损坏/损坏。

E. g. 例如 in test environment, every execution of rake test clears the database to prevent side effects . test环境中, 每次执行rake test清除数据库,以防止产生副作用 rspec automatically sets test environment for you. rspec自动为您设置test环境。

So, in your case, you should migrate your test database : 因此,就您而言,您应该迁移测试数据库

RAILS_ENV=test rake db:migrate:status
RAILS_ENV=test rake db:migrate

Hope it helps. 希望能帮助到你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么要求我运行“rake db:migrate RAILS_ENV=test”? - Why am I asked to run 'rake db:migrate RAILS_ENV=test'? 为什么要求我运行“ rake db:migrate RAILS_ENV = test”? - Why am I being asked to RUN 'rake db:migrate RAILS_ENV=test'? 耙db:migrate RAILS_ENV =开发 - rake db:migrate RAILS_ENV=development Bundle Exec Rake Test 和 rails db:migrate RAILS_ENV=test 不工作 - Bundle Exec Rake Test and rails db:migrate RAILS_ENV=test is not working 我为什么得到:迁移正在等待中。 要解决此问题,请运行:bin / rake db:migrate RAILS_ENV = development - Why am I getting: Migrations are pending. To resolve this issue, run: bin/rake db:migrate RAILS_ENV=development 该命令的作用是什么:rake db:migrate RAILS_ENV = test - What does this command do: rake db:migrate RAILS_ENV=test 迁移正在进行中; 运行“ rake db:migrate RAILS_ENV = development”来解决此问题。 - Migrations are pending; run 'rake db:migrate RAILS_ENV=development' to resolve this issue.? 迁移待定; 运行“bin/rake db:migrate RAILS_ENV=development”来解决这个问题[无法继续] - Migrations are pending; run 'bin/rake db:migrate RAILS_ENV=development' to resolve this issue [unable to proceed] 迁移正在等待中。 要解决此问题,请运行:bin / rake db:migrate RAILS_ENV = development - Migrations are pending. To resolve this issue, run: bin/rake db:migrate RAILS_ENV=development ActiveRecord :: PendingMigrationError:迁移正在挂起。 要解决此问题,请运行:bin / rake db:migrate RAILS_ENV = development - ActiveRecord::PendingMigrationError: Migrations are pending. To resolve this issue, run: bin/rake db:migrate RAILS_ENV=development
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM