我一直在尝试运行rake db:test:clone_structure
,但它一直无法重建数据库。我终于看了一下任务本身:
task :clone_structure => [ "db:structure:dump", "db:test:load_structure" ]
当我运行跟踪时,我注意到它db:test:load_structure
没有被执行:
$ rake db:test:clone_structure --trace
** Invoke db:test:clone_structure (first_time)
** Invoke db:structure:dump (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:structure:dump
** Invoke db:test:purge (first_time)
** Invoke environment
** Execute db:test:purge
** Execute db:test:clone_structure
现在,当我将clone_structure
任务更改为调用 load_structure
...
task :clone_structure => [ "db:structure:dump", "db:test:load_structure" ] do
db_namespace["test:load_structure"].invoke
end
...一切都突然起作用了!
$ rake db:test:prepare --trace
** Invoke db:test:clone_structure (first_time)
** Invoke db:structure:dump (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:structure:dump
** Invoke db:test:purge (first_time)
** Invoke environment
** Execute db:test:purge
** Execute db:test:clone_structure
** Invoke db:test:load_structure (first_time)
** Invoke db:test:purge
** Execute db:test:load_structure
** Invoke db:structure:load (first_time)
** Invoke environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:structure:load
什么可能导致这种行为?我正在使用 Rails 3.2.14 和 Rake 10.1.0。
更新:我将 Rails 从 3.2.11 升级到 3.2.13,但它仍然是一个问题。
更新了第二个:我将 Rails 升级到 3.2.14 并将 Rake 升级到 10.1.0,但这仍然是一个问题