[英]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环境:
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.