奇怪的rake db:迁移输出

时间:2015-03-10 03:44:54

标签: ruby-on-rails ruby rake rails-activerecord

为什么rake db:migrate运行Execute db:schema:dump我的输出全部搞砸了(显示SQL)。

看起来像这样:

  ActiveRecord::SchemaMigration Load (0.5ms)  SELECT "schema_migrations".* FROM "schema_migrations"
   (3.7ms)  SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete
FROM pg_constraint c
JOIN pg_class t1 ON c.conrelid = t1.oid
JOIN pg_class t2 ON c.confrelid = t2.oid
JOIN pg_attribute a1 ON a1.attnum = c.conkey[1] AND a1.attrelid = t1.oid
JOIN pg_attribute a2 ON a2.attnum = c.confkey[1] AND a2.attrelid = t2.oid
JOIN pg_namespace t3 ON c.connamespace = t3.oid
WHERE c.contype = 'f'
  AND t1.relname = 'accounts'
  AND t3.nspname = ANY (current_schemas(false))
ORDER BY c.conname

   (3.2ms)  SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete
FROM pg_constraint c
JOIN pg_class t1 ON c.conrelid = t1.oid
JOIN pg_class t2 ON c.confrelid = t2.oid
JOIN pg_attribute a1 ON a1.attnum = c.conkey[1] AND a1.attrelid = t1.oid
JOIN pg_attribute a2 ON a2.attnum = c.confkey[1] AND a2.attrelid = t2.oid
JOIN pg_namespace t3 ON c.connamespace = t3.oid
WHERE c.contype = 'f'
  AND t1.relname = 'deliveries'
  AND t3.nspname = ANY (current_schemas(false))
ORDER BY c.conname

   (3.2ms)  SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete
FROM pg_constraint c
JOIN pg_class t1 ON c.conrelid = t1.oid
JOIN pg_class t2 ON c.confrelid = t2.oid
JOIN pg_attribute a1 ON a1.attnum = c.conkey[1] AND a1.attrelid = t1.oid
JOIN pg_attribute a2 ON a2.attnum = c.confkey[1] AND a2.attrelid = t2.oid
JOIN pg_namespace t3 ON c.connamespace = t3.oid
WHERE c.contype = 'f'
  AND t1.relname = 'posts'
  AND t3.nspname = ANY (current_schemas(false))
ORDER BY c.conname

Trace显示了这一点:

** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
** Invoke db:_dump (first_time)
** Execute db:_dump
** Invoke db:schema:dump (first_time)
** Invoke environment 
** Invoke db:load_config 
** Execute db:schema:dump

这是在将rails 4.1.6升级到rails 4.2.0后开始的。

为什么会这样?

3 个答案:

答案 0 :(得分:4)

我得到这个奇怪的神秘SQL SQL输出的原因是因为我的gemfile中有Heroku的rails_12factor gem而没有分组到:production。

解决方案是:

group :production do
  gem 'rails_12factor'
end

并运行bundle

答案 1 :(得分:1)

升级到Rails 4.2.1之后我遇到了同样的问题,阻止我通过Codeship部署迁移,期望rake db:migrate的特定输出考虑推送成功。

config.log_level = :info中设置config/environments/production.rb为我解决了问题,大概是因为日志级别在:debug级别过于冗长。

答案 2 :(得分:0)

This discussion解决了" odd"输出给我:
只需在您的环境配置中将dump_schema_after_migration设置为false,如下所示:

/config/environments/development.rb

Application.configure do
  ...
  dump_schema_after_migration = false
  ...
end

修改
在大多数情况下,这不是您想要做的,因为您需要在版本控制中使用schema.rb