NameError:未初始化的常量PG在迁移到VPS时

时间:2015-03-15 18:05:02

标签: postgresql ruby-on-rails-4 vps digital-ocean capistrano3

我正在使用Capistrano 3.0向VPS部署Rails应用程序。当我运行cap production deploy时,我最终会遇到以下错误。我正在使用Postgresql。

INFO [356ebea5] Running ~/.rvm/bin/rvm default do bundle exec rake db:migrate as deployer@ipaddress
DEBUG [356ebea5] Command: cd /home/deployer/scoutqatar/releases/20150315174921 && ( RAILS_ENV=production ~/.rvm/bin/rvm default do bundle exec rake db:migrate )
DEBUG [356ebea5]    rake aborted!
DEBUG [356ebea5]    NameError: uninitialized constant PG

似乎我在迁移过程中遇到错误。

我在VPS中有config/database.yml个文件,其中包含以下内容:

development:
  adapter: postgresql
  encoding: utf8
  database: dohaguide_development
  pool: 5
  username: user
  password: pass

test: &TEST
  adapter: postgresql
  encoding: utf8
  database: dohaguide_test
  pool: 5
  username: user
  password: pass

production:
  adapter: postgresql
  encoding: utf8
  database: dohaguide_production
  pool: 5
  username: user    
  password: pass

我在VPS中创建了上述数据库。

我的deploy.rb文件包含以下内容

# Default value for :linked_files is []
set :linked_files, %w{config/database.yml}

# Default value for linked_dirs is []
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}

namespace :deploy do

  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      # Your restart mechanism here, for example:
      execute :touch, release_path.join('tmp/restart.txt')
    end
  end

  after :publishing, :restart

  after :restart, :clear_cache do
    on roles(:web), in: :groups, limit: 3, wait: 10 do
      # Here we can do anything such as:
      # within release_path do
      #   execute :rake, 'cache:clear'
      # end
    end
  end

  after :finishing, 'deploy:cleanup'

end

我一直试图弄清楚错误的原因但却找不到任何错误。 有人可以指导我正确的方向

1 个答案:

答案 0 :(得分:0)

似乎问题是db用户名与为VPS部署创建的用户名不同。