programing

rake db : create가 postgresql에서 "데이터베이스가 존재하지 않음"오류를 발생시킵니다.

kingscode 2021. 1. 17. 10:58
반응형

rake db : create가 postgresql에서 "데이터베이스가 존재하지 않음"오류를 발생시킵니다.


Debian 7에서 postgresql 9.1과 함께 rails 4.1.5를 사용하고 있으며 개발 환경에서 데이터베이스를 만들 수 없습니다. 내가 달릴 때

bin/rake db:create

나는 얻다

home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/postgresql_adapter.rb:898:in `rescue in connect': FATAL:  database "direct-dev" does not exist
Run `$ bin/rake db:create db:migrate` to create your database (ActiveRecord::NoDatabaseError)
from /home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `connect'
from ...

데이터베이스를 만들려고하므로 당연히 존재하지 않습니다. 그러나 레일은 그것을 만들어야합니다 ... 여기 내 config / database.yml이 있습니다.

default: &default
  adapter: postgresql
  encoding: unicode
  pool: 5

development:
  <<: *default
  database: direct-dev

다음은 postgresql 로그의 일부입니다.

2014-09-01 19:30:40 CEST LOG:  connection received: host=[local]
2014-09-01 19:30:40 CEST LOG:  connection authorized: user=rs database=direct-dev
2014-09-01 19:30:40 CEST FATAL:  database "direct-dev" does not exist

포인터가 있습니까? 나는 한 시간 넘게 여기에 있었지만 왜 이런 일이 일어나는지 이해할 수 없습니다 ...

감사!


4.1 레일 스프링 프리 로더와 함께 제공을 하고,

새로운 Rails 4.1 애플리케이션은 "springified"binstub과 함께 제공됩니다. 즉, bin / rails 및 bin / rake는 사전로드 된 스프링 환경을 자동으로 활용합니다.

즉, "springified" bin/rake가 앱을 미리로드하려고 시도하고, 이로 인해 초기화 프로그램을 실행하려고 시도하여 문제가 발생합니다.

이 문제를 해결 / 해결하려면 스프링없이 초기 설정 레이크 작업을 실행해야합니다. 이를 달성하는 한 가지 방법은 대신 번 들러로 실행하는 것입니다.

bundle exec rake db:create

문제를 발견했습니다 ...

Rails 이니셜 라이저와 관련이 있습니다. Rails는 실행하기 전에 모든 이니셜 라이저를로드하는 것 같습니다 bin/rake db:create.

그리고이 특정 애플리케이션에는 ActiveRecord 모델에 의존하는 몇 가지 사용자 지정 이니셜 라이저가 있습니다 (이는 생성되는 데이터베이스, 사용 가능한 데이터베이스 및 해당 테이블에 따라 달라짐).

따라서 rake는 실제로 작업을 실행하지 못하며 이니셜 라이저를 실행할 때 실패합니다. 전체 오류 메시지 로그를주의 깊게 읽었는지 알았어 야했습니다. 다음은 전체 로그입니다 (아래 굵은 글씨로 잘못된 줄 참조).

/home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/postgresql_adapter.rb:898:in`rescue in connect ': FATAL : 데이터베이스 "ds-dev " 존재하지 않는다
`$ bin / rake db : create db : migrate`를 실행하여 데이터베이스를 만듭니다 (ActiveRecord :: NoDatabaseError).
/home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in`connect '에서
/home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/postgresql_adapter.rb:568에서 :`initialize '
/home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in`new '에서
/home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in`postgresql_connection '에서
/home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:435:in`new_connection '에서
/home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:445:in`checkout_new_connection '에서
/home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in`acquire_connection '에서
from /home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:351:in`block in checkout '
/home/rs/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/monitor.rb:211:'mon_synchronize '에서
/home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:350:in`checkout '에서
from /home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in`block in connection '
/home/rs/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/monitor.rb:211:'mon_synchronize '에서
/home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in`connection '에서
/home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:541:'retrieve_connection '에서
/home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_handling.rb:113:'retrieve_connection '에서
/home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_handling.rb:87:in`connection '에서
from /home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/model_schema.rb:209:in`table_exists? '
/home/rs/pr/ds/app/models/property.rb:32:in`get '에서
/home/rs/pr/ds/config/initializers/custom/setup_mail.rb:3:in` '에서
/home/rs/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:241 : '로드'에서
from /home/rs/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:241:in`block in load '
/home/rs/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:232:in`load_dependency '에서
/home/rs/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:241 : '로드'에서
from /home/rs/.rvm/gems/ruby-2.1.2/gems/railties-4.1.5/lib/rails/engine.rb:648:in`block in load_config_initializer '
/home/rs/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.5/lib/active_support/notifications.rb:161:`instrument '에서
/home/rs/.rvm/gems/ruby-2.1.2/gems/railties-4.1.5/lib/rails/engine.rb:647:`load_config_initializer '에서
from /home/rs/.rvm/gems/ruby-2.1.2/gems/railties-4.1.5/lib/rails/engine.rb:612:in`block (2 levels) in '
/home/rs/.rvm/gems/ruby-2.1.2/gems/railties-4.1.5/lib/rails/engine.rb:611 : '각각'에서
/home/rs/.rvm/gems/ruby-2.1.2/gems/railties-4.1.5/lib/rails/engine.rb:611:in`block in '
/home/rs/.rvm/gems/ruby-2.1.2/gems/railties-4.1.5/lib/rails/initializable.rb:30에서 :`instance_exec '에서
/home/rs/.rvm/gems/ruby-2.1.2/gems/railties-4.1.5/lib/rails/initializable.rb:30:in`run '에서
from /home/rs/.rvm/gems/ruby-2.1.2/gems/railties-4.1.5/lib/rails/initializable.rb:55:in`block in run_initializers '
from /home/rs/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:226:in`block in tsort_each '
from /home/rs/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:348:in`block (2 levels) in each_strongly_connected_component '
from /home/rs/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:418:in`block (2 levels) in each_strongly_connected_component_from '
/home/rs/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:427:'each_strongly_connected_component_from '에서
from /home/rs/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:417:in`block in each_strongly_connected_component_from '
/home/rs/.rvm/gems/ruby-2.1.2/gems/railties-4.1.5/lib/rails/initializable.rb:44:in`each '에서
/home/rs/.rvm/gems/ruby-2.1.2/gems/railties-4.1.5/lib/rails/initializable.rb:44:in`tsort_each_child '에서
from /home/rs/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:411:in`call '
from /home/rs/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:411:in`each_strongly_connected_component_from '
from /home/rs/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:347:in`block in each_strongly_connected_component '
/home/rs/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:in`each '에서
/home/rs/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:in`call '에서
/home/rs/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:'each_strongly_connected_component '에서
/home/rs/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:224:'tsort_each '에서
/home/rs/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:205:in`tsort_each '에서
/home/rs/.rvm/gems/ruby-2.1.2/gems/railties-4.1.5/lib/rails/initializable.rb:54:in`run_initializers '에서
/home/rs/.rvm/gems/ruby-2.1.2/gems/railties-4.1.5/lib/rails/application.rb:300:in`initialize! '
/home/rs/pr/ds/config/environment.rb:5:in` '에서
/home/rs/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:247:'require '에서
from /home/rs/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:247:in`block in require '
/home/rs/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:232:in`load_dependency '에서
/home/rs/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:247:'require '에서
/home/rs/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/application.rb:92:'preload '에서
/home/rs/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/application.rb:140:'serve '에서
from /home/rs/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/application.rb:128:in`block in run '
/home/rs/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/application.rb:122:in`loop '에서
/home/rs/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/application.rb:122:in`run '에서
/home/rs/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/application/boot.rb:18:in` '에서
/home/rs/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:'require '에서
/home/rs/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:'require '에서
-e : 1 : in` '에서

이니셜 라이저에서 모델 종속성을 제거하기 위해 코드를 리팩토링하는 작업을 수행 할 것입니다 (매우 나쁜 관행 임에 틀림 없음).


이 명령을 실행 해보십시오.

bin/rake db:create RAILS_ENV=development

또는이 명령-

bin/rake db:migrate RAILS_ENV=development

오늘 (OS X에서) 같은 문제가있었습니다.

해결 방법 :

psql -U postgres
CREATE ROLE rolename WITH CREATEDB LOGIN;

\du생성되었는지 확인하는 데 사용 합니다.

\password rolename해당 사용자 / 역할에 대한 암호를 만드는 데 사용 합니다 .

그런 다음 DB를 설정할 수 있습니다. bundle exec rake db:migrate


어떤 솔루션도 나를 위해 일하지 않았지만 이것은 나를 위해 일했습니다.

$ brew services list
$ brew services restart postgresql

is04가 지적했듯이 적어도 usernamedatabase.yml에 값이 필요하다는 두 가지 문제가 있습니다.

You also need to create the postgres role:

su - postgres
create role direct-dev with createdb login password 'password1'

None of the solutions worked for me, but then I saw that some answers mentioned preloading as part of the problem. I realized I had config.eager_load = true in config/environments/development.rb. I changed it to false and it solved the problem.

ReferenceURL : https://stackoverflow.com/questions/25611004/rake-dbcreate-throws-database-does-not-exist-error-with-postgresql

반응형