gpt4 book ai didi

ruby-on-rails - Ruby on Rails 命令 rake db :migrate not working using PostgreSQL

转载 作者:行者123 更新时间:2023-11-29 13:32:21 30 4
gpt4 key购买 nike

正如我在标题中提到的,我在 Ruby on Rails 上使用 PostgreSQL 数据库,因为 heroku 不再支持 MySQLite。在我运行命令 rails generate scaffold User name:string email:string 之后一切顺利,但是当我尝试 rake db:migrate 时它抛出了一些错误。搜索了一段时间后,我将 Rake 从 10.0.1 降级到 0.8.7。这是我使用 --trace 时遇到的错误:

> /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake/alt_system.rb:32:
> Use RbConfig instead of obsolete and deprecated Config. (in
> /home/Roma/rails_projects/coise)
> ** Invoke db:migrate (first_time)
> ** Invoke environment (first_time)
> ** Execute environment
> ** Execute db:migrate rake aborted! could not connect to server: Connection refused
> Is the server running on host "localhost" (127.0.0.1) and accepting
> TCP/IP connections on port 5432? /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:928:in `initialize'
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:928:in `new'
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:928:in `connect'
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:228:in `initialize'
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:25:in
> `new'
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:25:in
> `postgresql_connection'
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:230:in
> `new_connection'
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:238:in
> `checkout_new_connection'
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:194:in
> `block (2 levels) in checkout'
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:190:in
> `loop'
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:190:in
> `block in checkout' /usr/lib/ruby/1.9.1/monitor.rb:211:in
> `mon_synchronize'
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:189:in
> `checkout'
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:96:in
> `connection'
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:318:in
> `retrieve_connection'
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:97:in `retrieve_connection'
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:89:in `connection'
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/migration.rb:486:in
> `initialize'
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/migration.rb:433:in
> `new'
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/migration.rb:433:in
> `up'
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/migration.rb:415:in
> `migrate'
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/railties/databases.rake:142:in
> `block (2 levels) in <top (required)>'
> /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:636:in `call'
> /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:636:in `block in
> execute' /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:631:in
> `each' /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:631:in
> `execute' /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:597:in
> `block in invoke_with_call_chain'
> /usr/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
> /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:590:in
> `invoke_with_call_chain'
> /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
> /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2051:in
> `invoke_task'
> /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in `block (2
> levels) in top_level'
> /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
> /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in `block in
> top_level'
> /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2068:in
> `standard_exception_handling'
> /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2023:in
> `top_level'
> /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2001:in `block in
> run' /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2068:in
> `standard_exception_handling'
> /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
> /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/bin/rake:31:in `<top
> (required)>' /usr/bin/rake:23:in `load' /usr/bin/rake:23:in `<main>'

我现在真的不知道该怎么办。我还将展示我的 database.yml 文件(根据搜索时遇到的提示进行了一些更改):

development:
adapter: postgresql
encoding: unicode
database: coise_development
pool: 5
username: coise
password:
host: localhost
port: 5432

test:
adapter: postgresql
encoding: unicode
database: coise_test
pool: 5
username: coise
password:
host: localhost
port: 5432

production:
adapter: postgresql
encoding: unicode
database: coise_production
pool: 5
username: coise
password:

最佳答案

我进步了。我能够通过这篇 StackOverflow 帖子 - Enable Postgresql in Cygwin - 启动并运行我的 PostGreSql 服务。最后,我所要做的就是根据启动 PostGreSql 服务的用户更改我的 database.yml 文件用户名和数据库字段,在我的例子中是“Roma”。

最后,命令 rake db:migrate 没有遇到任何问题,就像我推送到 heroku 一样,完美无缺。我仍然不明白的唯一事情是 heroku 托管,因为我的用户页面(我使用 Rails scaffold 命令添加的表)尚不可用。我的 heroku 告诉我应该有更多的“Dynos”并升级到“Production Postgresql Database”。我不确定这是否意味着托管需要一段时间才能完成,或者我的应用程序是否真的有问题,但我不得不说生成的数据库非常基本和简单。如果任何版主认为这应该变成新的 StackOverflow 帖子,请告诉我。

关于ruby-on-rails - Ruby on Rails 命令 rake db :migrate not working using PostgreSQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20504315/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com