Max*_*s S 1 sqlite postgresql ruby-on-rails
我第一次尝试将我的rails应用程序部署到Heroku,遇到了很多问题.应用程序崩溃,您可以查看映像中的日志:http
://i.stack.imgur.com/bsx1b.png
更糟糕的是,当我尝试在本地查看我的应用程序时,它无法在postgreSQL环境中工作当我回到database.yml中使用sqLite3时工作正常.我认为问题可能是我实际上必须安装postgreSQL,除了添加pg gem和运行bundle install.
我继续使用一键安装程序(Windows 7 64位)安装PostgreSQL.重启后,一个简单的rails服务器或bundle install命令开始失败,所以我重新安装了整个ruby和rails.
现在rails server命令工作正常,当我尝试在本地环境中查看我的应用程序时,它会提示不同的错误.所以现在我有pgAdmin III和Rails
PG::Error
fe_sendauth: no password supplied
Run Code Online (Sandbox Code Playgroud)
我试着遵循这个,但我找不到"pg_hba.conf".我想答案是基于不同的操作系统.
而现在再次,捆绑器不工作,给我错误......
问题: 1)使用一键安装程序安装postgreSQL是否正确?因为这导致我的ROR以某种方式"崩溃",我不得不重新安装rails.2)我想我将删除与postgreSQL相关的所有内容,重新安装Rails,并从头开始.我必须采取哪些步骤?我看过的所有参考文献似乎都不适合Windows环境.
在我的gemfile中,我有
gem 'pg'
gem 'thin'
Run Code Online (Sandbox Code Playgroud)
在我的数据库中,我有
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: postgresql
encoding: utf8
database: mangfeel_development
pool: 5
timeout: 5000
# 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:
adapter: postgresql
encoding: utf8
database: mangfeel_test
pool: 5
timeout: 5000
production:
adapter: postgresql
encoding: utf8
database: mangfeel_production
pool: 5
timeout: 5000
Run Code Online (Sandbox Code Playgroud)
安装PostgreSQL之后我现在遇到的错误:
c:\ruby\myapp>rails server
C:/Program Files (x86)/ruby-1.9.2/lib/ruby/site_ruby/1.9.1/rubygems.rb:926:in `report_activate_error': Could not find RubyGem railties (>= 0) (Gem::LoadError)
from C:/Program Files (x86)/ruby-1.9.2/lib/ruby/site_ruby/1.9.1/rubygems.rb:244:in `activate_dep'
from C:/Program Files (x86)/ruby-1.9.2/lib/ruby/site_ruby/1.9.1/rubygems.rb:236:in `activate'
from C:/Program Files (x86)/ruby-1.9.2/lib/ruby/site_ruby/1.9.1/rubygems.rb:1307:in `gem'
from C:/RailsInstaller/Ruby1.9.3/bin/rails:18:in `<main>'
Run Code Online (Sandbox Code Playgroud)
当我运行bundle install时:
Gem::InstallError: The 'json' native gem requires installed build tools
Please update your PATH to include build tools or download the DevKit
from 'http://rubyinstaller.org/downloads' and follow the instructions
at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'
An error occurred while installing json (1.7.5), and Bundler cannot continue.
Make sure that `gem install json -v '1.7.5'` succeeds before bundling.
Run Code Online (Sandbox Code Playgroud)
所以我将完全删除pgAdminIII,PostgreSQL,Ruby on Rails,并从头开始.
我认为部署不会那么困难,但是从SQLite3迁移到PostgreSQL需要比我想象的更多的时间和精力.我真的很感激这个问题的一些帮助.
-------------------------------------------------- -------------------------------------------------- --------------------
更新:重新安装一切后,我将再次设置SCRATCH设置.
我检查了我的SQLite3版本应用程序运行正常.所以我开始设置postgreSQL.我第一次设置postgreSQL时遇到以下错误.通过设置,我的意思是编辑config/database.yml并安装gem'pg'并删除gem的sqlite3.当我尝试连接到localhost:3000时,出现以下错误:
ActiveRecord::ConnectionNotEstablished
Run Code Online (Sandbox Code Playgroud)
经过一些研究,我发现设置数据库可能会有更多步骤.所以我运行了bundle命令,
bundle exec rake db:setup
Run Code Online (Sandbox Code Playgroud)
但是在控制台中,当我运行bundle exec rake db:setup时出现以下错误.
Couldn't create database for {"adapter"=>"postgresql", "host"=>"localhost", "encoding"=>"utf8", "database"=>"db/myapp_test", "pool"=>5, "timeout"=>5000}
rake aborted!
could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
c:/ruby/myapp/config/environment.rb:5:in `<top (required)>'
Tasks: TOP => db:schema:load => environment
Run Code Online (Sandbox Code Playgroud)
当我尝试连接到localhost:3000时,我再次收到上述错误,而不是ActiveRecord :: ConnectionNotEstablished.
问题:我做错了什么,如何解决问题?
如果您有错误:
PG::Error
fe_sendauth: no password supplied
Run Code Online (Sandbox Code Playgroud)
你有好消息,你的应用程序现在可以使用PostgreSQL数据库.(但你需要配置一些东西)
安装PostgreSQL后,您可以通过命令使用PostgreSQL创建新的rails应用程序:
rails new my_app -d postgresql
Run Code Online (Sandbox Code Playgroud)
这database.yml
将被创建:
development:
adapter: postgresql
encoding: unicode
database: my_app_development
pool: 5
username: my_app
password:
test:
adapter: postgresql
encoding: unicode
database: my_app_test
pool: 5
username: my_app
password:
production:
adapter: postgresql
encoding: unicode
database: my_app_production
pool: 5
username: my_app
password:
Run Code Online (Sandbox Code Playgroud)
你看,三个数据库有username
和password
字段,这是Postgresql中的帐户用户,database.yaml
该用户将创建三个数据库文件.所以,你需要提供username
和password
它.安装Postgresql后默认,它创建了一个用户名是postgresql
密码的用户postgresql
.你可以使用它.
如果您想使用其他用户,只需pgAdmin III
右键单击打开并创建新用户,然后Login Roles
选择New login role
使用密码创建新用户.然后将该用户名和密码放入database.yaml
文件中.
在那之后,你现在需要的只是找到并打开pg_hba.conf
文件来为app配置一些可以使用PostgreSQL.我很长时间没有使用Windows,所以我不确定它在哪里,但你可以在文件夹中找到你安装的PostgreSQL.例如,如果您在E:\
分区上安装,也许您可以在以下位置找到它:
E:\PostgreSQL\version\data
找到后,打开并找到一行:
# "local" is for Unix domain socket connections only
local all all ident sameuser
Run Code Online (Sandbox Code Playgroud)
将其更改为:
# "local" is for Unix domain socket connections only
local all all md5
Run Code Online (Sandbox Code Playgroud)
然后重新启动Postgresql数据库.要为app创建数据库,请运行rake db:create
或rake db:create:all
.现在你的应用程序现在可以使用PostgreSQL数据库,非常高兴:).
归档时间: |
|
查看次数: |
3015 次 |
最近记录: |