当前位置: 首页 > 知识库问答 >
问题:

Parallel_tests数据库不存在

司毅庵
2023-03-14

我使用parallel_testsgem在配置项中运行我的Rails6应用程序测试。在日志中,我看到正在创建具有env[TEST_ENV_NUMBER]的所有9个数据库,但它只是失败了,说这些数据库不存在。

我运行的命令是:

bin/bundle install
bin/bundle exec rake parallel:setup
bin/bundle exec rake parallel:spec

日志如下:

Created database 'my_db_name4'
 set_config 
------------
 
(1 row)
Created database 'my_db_name'
 set_config 
------------
 
(1 row)
Created database 'my_db_name2'
 set_config 
------------
 
(1 row)
Created database 'my_db_name5'
 set_config 
------------
 
(1 row)
Created database 'my_db_name7'
 set_config 
------------
 
(1 row)
Created database 'my_db_name8'
 set_config 
------------
 
(1 row)
Created database 'my_db_name6'
 set_config 
------------
 
(1 row)
Created database 'my_db_name3'
 set_config 
------------
 
(1 row)

bin/bundle exec rake parallel:spec

rake aborted!
ActiveRecord::NoDatabaseError: FATAL:  database "my_db_name1" does not exist
/usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_adapters/postgresql_adapter.rb:50:in `rescue in postgresql_connection'
/usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_adapters/postgresql_adapter.rb:33:in `postgresql_connection'
/usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:887:in `new_connection'
/usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:931:in `checkout_new_connection'
/usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:910:in `try_to_checkout_new_connection'
/usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:871:in `acquire_connection'
/usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:593:in `checkout'
/usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:437:in `connection'
/usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:1119:in `retrieve_connection'
/usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_handling.rb:221:in `retrieve_connection'
/usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_handling.rb:189:in `connection'
/usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/railties/databases.rake:261:in `block (3 levels) in <main>'
/usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/railties/databases.rake:258:in `each'
/usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/railties/databases.rake:258:in `flat_map'
/usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/railties/databases.rake:258:in `block (2 levels) in <main>'
/usr/local/bundle/gems/parallel_tests-3.0.0/lib/parallel_tests/tasks.rb:71:in `block in check_for_pending_migrations'
/usr/local/bundle/gems/parallel_tests-3.0.0/lib/parallel_tests/tasks.rb:69:in `each'
/usr/local/bundle/gems/parallel_tests-3.0.0/lib/parallel_tests/tasks.rb:69:in `check_for_pending_migrations'
/usr/local/bundle/gems/parallel_tests-3.0.0/lib/parallel_tests/tasks.rb:183:in `block (3 levels) in <main>'
bin/bundle:113:in `load'
bin/bundle:113:in `<main>'
Caused by:
PG::ConnectionBad: FATAL:  database "my_db_name1" does not exist
/usr/local/bundle/gems/pg-1.2.3/lib/pg.rb:58:in `initialize'
/usr/local/bundle/gems/pg-1.2.3/lib/pg.rb:58:in `new'
/usr/local/bundle/gems/pg-1.2.3/lib/pg.rb:58:in `connect'
/usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_adapters/postgresql_adapter.rb:46:in `postgresql_connection'
/usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:887:in `new_connection'
/usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:931:in `checkout_new_connection'
/usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:910:in `try_to_checkout_new_connection'
/usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:871:in `acquire_connection'
/usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:593:in `checkout'
/usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:437:in `connection'
/usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:1119:in `retrieve_connection'
/usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_handling.rb:221:in `retrieve_connection'
/usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_handling.rb:189:in `connection'
/usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/railties/databases.rake:261:in `block (3 levels) in <main>'
/usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/railties/databases.rake:258:in `each'
/usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/railties/databases.rake:258:in `flat_map'
/usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/railties/databases.rake:258:in `block (2 levels) in <main>'
/usr/local/bundle/gems/parallel_tests-3.0.0/lib/parallel_tests/tasks.rb:71:in `block in check_for_pending_migrations'
/usr/local/bundle/gems/parallel_tests-3.0.0/lib/parallel_tests/tasks.rb:69:in `each'
/usr/local/bundle/gems/parallel_tests-3.0.0/lib/parallel_tests/tasks.rb:69:in `check_for_pending_migrations'
/usr/local/bundle/gems/parallel_tests-3.0.0/lib/parallel_tests/tasks.rb:183:in `block (3 levels) in <main>'
bin/bundle:113:in `load'
bin/bundle:113:in `<main>'
Tasks: TOP => db:abort_if_pending_migrations
(See full trace by running task with --trace)```

Am I doing something wrong? I suspect databases are being destroyed somewhere, but I don't know where to look.

共有1个答案

段兴为
2023-03-14

所以,这很容易,但很难找到=(我发现我在配置项中把test_env_numberenv变量设置为1。所以,它试图从每个进程连接到数据库my_db_name1。我移除这个变量后,一切都开始正常工作了。我仍然很感兴趣的是,为什么这个数据库没有像@cdadityang在注释中指出的那样创建。

 类似资料:
  • 我能够通过一个PHP脚本用这些完全相同的凭证连接到< code>protomolecule数据库。如图所示,试图在PhpStorm中设置它失败了。 如果我将数据库更改为默认的数据库,它在PhpStom中连接得很好。我不明白为什么用户只能连接到而不是其他任何东西。 我尝试设置新用户和新数据库无济于事。 编辑:根据要求添加了下面的工作PHP脚本设置。

  • 似乎我甚至无法运行控制台来创建它试图查找的数据库。同样的事情也发生在我刚刚跑步的时候: 或者从“应用程序”下拉菜单中启动psql: 计算机状态: 我也试图通过自制安装PostgreSql,但我也遇到了同样的问题。我还阅读了应用程序文档页面,其中指出: 当postgres.app首次启动时,它会创建$user数据库,当未指定时,这是psql的默认数据库。默认用户是$user,没有密码。 所以看起来应

  • 奇怪的错误。感谢所有帮助。 这是我的数据库。 当我手动创建数据库并尝试使用它们时,例如 ,我收到以下错误: 当我尝试删除数据库时,我收到以下错误: 如果我尝试使用<code>rake db:create:all</code>创建数据库,我会得到以下错误: 看来我的数据库。yml还可以。但出于某种原因,它正在寻找一个名为postgres的数据库,而我的数据库中没有这个数据库。yml。 感谢任何帮助。

  • 我尝试使用pg_dump命令导出PostgreSQL数据库(数据库名ari_company): 然后我得到了这个错误: 但当我运行默认数据库(postgres)时,它会工作并转储。sql被创建。使用命令

  • 一、内存数据库: 在SQLite中,数据库通常是存储在磁盘文件中的。然而在有些情况下,我们可以让数据库始终驻留在内存中。最常用的一种方式是在调用sqlite3_open()的时候,数据库文件名参数传递":memory:",如: rc = sqlite3_open(":memory:", &db); 在调用完以上函数后,不会有任何磁盘文件被生成,取而代之的是,一个新的数据库在纯内存中被成功创建了。

  • 问题内容: 有创建数据库的类似物吗? 背景:我正在编写一个脚本,以在未知系统上的PostgreSQL中自动设置架构。我不确定数据库(甚至是架构的一部分)是否已经部署,因此如果某些结构已经存在,我想构建代码以使其不会失败(或者理想情况下甚至显示错误)。我想区分导致我无法创建数据库的错误(因此中止将来的架构更改,因为它们将无法工作)。 问题答案: 否,但是您可以查询pg_catalog.pg_data