我嘗試部署我的應用程序,當我運行命令Ruby on Rails的PG :: ConnectionBad
rails server -b $IP -p $PORT
我得到一個errr
PG :: ConnectionBad
無法連接到服務器:連接被拒絕服務器是否在本地運行並接受Unix域套接字「/var/run/postgresql/.s.PGSQL.5432」上的連接?
提取的源(左右線#56):
### Convenience alias for PG::Connection.new.
def self::connect(*args)
return PG::Connection.new(*args)
end
我的database.yml是
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: 5
development:
<<: *default
database: db/development.sqlite3
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3
======= UPDATE =====
我現在得到一個錯誤,說ActiveRecord :: NoDatabaseError, 致命:數據庫「sale_development」不存在
當我更新database.yml,以
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: 5
development:
adapter: postgresql
encoding: unicode
database: sale_development
pool: 5
test: &test
adapter: postgresql
encoding: unicode
database: sale_test
pool: 5
production:
adapter: postgresql
encoding: unicode
database: sale_production
pool: 5
host: localhost
username: sale
password: <%= ENV['SALE_DATABASE_PASSWORD'] %>
=>引導彪馬 CKOUT ' 網絡的控制檯(3.5.1)LIB/web_console/middleware.rb:135:在call_app'actionpack (5.1.1) lib/action_dispatch/middleware/request_id.rb:25:in
呼叫' 機架(2.0。 3)lib/rack/method_override.rb:22:在call' rack (2.0.3) lib/rack/runtime.rb:22:in
調用' activesupport(5.1.1)lib/active_support/cache/strategy/local_cache_middleware.rb:27:call' puma (3.8.2) lib/puma/thread_pool.rb:120:in
block in spawn_thread' ActiveRecord :: StatementInvalid:PG :: InvalidParameterValue:錯誤:新編碼(UTF8)是incompat17:在create' /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-5.1.1/lib/active_record/tasks/database_tasks.rb:303:in
每個' /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-5.1.1/lib/activ e_record/tasks/database_tasks.rb:3Tasks:TOP => db:create ActiveRecord :: StatementInvalid:PG :: InvalidParameterValue:ERROR:new encoding(UTF8)is incompat17:in create' /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-5.1.1/lib/active_record/tasks/database_tasks.rb:303:in
each' /usr/local/rvm/gems /ruby-2.3.0/gems/activerecord-5.1.1/lib/active_record/tasks/database_tasks.rb:303:in each_current_configuration' /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-5.1.1/lib/active_record/tasks/database_tasks.rb:136:in
create_current' /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord -5.1.1/lib/active_record/railties/databases.rake:2/usr/local/rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:eval' /usr/local/rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in
' /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1007:在up' /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-5.1.1/lib/active_record/tasks/database_tasks.rb:303:in
每個' /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-5.1。 1/LIB/active_record /任務/ database_tasks.rb:3的/ usr /本地/ RVM /寶石/紅寶石2.3.0 /寶石/的ActiveSupport-5.1.1/LIB/active_support /沉積/ usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-5.1.1/lib/active_record/tasks/database_tasks.rb:303:在each'/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-5.1.1/lib/active_record/tasks/database_tasks.rb:303:in
each_current_configuration'/ usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-5.1.1/lib/active_record/tasks/database_tasks.rb:136:在'/usr/local/rvm/gems/ruby-2.3中的create_current'/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-5.1.1/lib/active_record/railties/databases.rake:27:in
塊(2級)。 0/gems/rake-12.0.0/exe/rake:27:在<top (required)>' /usr/local/rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in
eval' /usr/local/rvm/gems/ruby-2.3。0 /斌/ ruby_executable_hooks:15:在`」 任務:TOP =>分貝:創建
===== UPDATE ====(通過運行與--trace任務查看完整的跡線)
的Gemfile
source 'https://rubygems.org'
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
gem 'pg'
# Use Puma as the app server
gem 'puma', '~> 3.7'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
gem 'bootstrap-sass'
gem "paperclip", "~> 5.0.0"
gem 'devise', '~> 4.3'
gem 'will_paginate', '~> 3.0'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
只需運行rake db:create來創建數據庫,然後運行rake db:如果已有模型,則遷移 – widjajayd
如果您的服務器新建且仍然沒有數據並且它的生產服務器運行RAILS_ENV = production耙分貝:創建,然後繼續RAILS_ENV =生產耙分貝:遷移 – widjajayd
我試過了,但得到了一長串錯誤 – bockdavidson