diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb
index <HASH>..<HASH> 100644
--- a/railties/lib/rails/application/configuration.rb
+++ b/railties/lib/rails/application/configuration.rb
@@ -178,7 +178,7 @@ module Rails
               values.reverse_merge!(shared)
             end
           end
-          loaded_yaml.delete("default")
+          loaded_yaml.reject! { |_, values| !values["database"] }
           Hash.new(shared).merge(loaded_yaml)
         elsif ENV["DATABASE_URL"]
           # Value from ENV['DATABASE_URL'] is set to default database connection
Reject empty database yamls

In #<I> I deleted the default configuration since that's what's
generated with the Rails app. Since someone could change the default
name instead delete any config that doesn't have a database so we can
avoid peppering our Rails tasks with conditionals to deal with invalid
database configs.