1

好的。我下载了这个社交网络服务器以在我的机器上进行本地测试,我已按照所有说明进行操作,但缺少迁移。

我一次又一次地进行迁移(命令是bundle exec rake db:migrate RAILS_ENV=development),我不断收到这个错误,看起来chewy图书馆是问题所在。或者其他什么,我以前从未使用过 Rails。

这些是我得到的日志的最后几行:

== 20170920024819 StatusIdsToTimestampIds: migrated (0.1932s) =================

Chewy strategies stack: [2] -> bypass, now bypass @ /var/lib/gems/2.5.0/gems/chewy-5.0.0/lib/chewy/railtie.rb:37
   (0.4ms)  BEGIN
  ActiveRecord::SchemaMigration Create (0.7ms)  INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"  [["version", "20170920024819"]]
   (0.6ms)  COMMIT
   (1.4ms)  COMMIT
   (1.1ms)  ROLLBACK
   (0.5ms)  SELECT pg_advisory_unlock(7061509875526502865)
rake aborted!
ActiveRecord::StatementInvalid: PG::ConnectionBad: connection is closed: SELECT pg_advisory_unlock(7061509875526502865)
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql/database_statements.rb:63:in `async_exec'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql/database_statements.rb:63:in `block (2 levels) in query'
/var/lib/gems/2.5.0/gems/activesupport-5.2.3/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads'
/var/lib/gems/2.5.0/gems/activesupport-5.2.3/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
/var/lib/gems/2.5.0/gems/activesupport-5.2.3/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql/database_statements.rb:62:in `block in query'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract_adapter.rb:581:in `block (2 levels) in log'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract_adapter.rb:580:in `block in log'
/var/lib/gems/2.5.0/gems/activesupport-5.2.3/lib/active_support/notifications/instrumenter.rb:23:in `instrument'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract_adapter.rb:571:in `log'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql/database_statements.rb:61:in `query'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/database_statements.rb:98:in `query_value'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:348:in `release_advisory_lock'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:1365:in `ensure in with_advisory_lock'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:1366:in `with_advisory_lock'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:1210:in `migrate'
/var/lib/gems/2.5.0/gems/chewy-5.0.0/lib/chewy/railtie.rb:37:in `block in migrate'
/var/lib/gems/2.5.0/gems/chewy-5.0.0/lib/chewy/strategy.rb:70:in `wrap'
/var/lib/gems/2.5.0/gems/chewy-5.0.0/lib/chewy.rb:201:in `strategy'
/var/lib/gems/2.5.0/gems/chewy-5.0.0/lib/chewy/railtie.rb:37:in `migrate'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:1036:in `up'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:1011:in `migrate'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/tasks/database_tasks.rb:172:in `migrate'
/var/lib/gems/2.5.0/gems/strong_migrations-0.4.0/lib/strong_migrations/database_tasks.rb:4:in `migrate'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/railties/databases.rake:60:in `block (2 levels) in <top (required)>'
/var/lib/gems/2.5.0/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'

Caused by:
[useless log lines removed]

随后,当我再次尝试进行迁移时,出现此错误:

== 20180402040909 CreateReportNotes: migrating ================================
-- create_table(:report_notes, {})
   (13.1ms)  CREATE TABLE "report_notes" ("id" bigserial primary key, "content" text NOT NULL, "report_id" bigint NOT NULL, "account_id" bigint NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
   (5.1ms)  CREATE  INDEX  "index_report_notes_on_report_id" ON "report_notes"  ("report_id")
   (4.1ms)  CREATE  INDEX  "index_report_notes_on_account_id" ON "report_notes"  ("account_id")
   -> 0.0326s
Chewy strategies stack: [2] -> bypass, now bypass @ /var/lib/gems/2.5.0/gems/chewy-5.0.0/lib/chewy/railtie.rb:37
   (1.3ms)  ROLLBACK
   (0.6ms)  SELECT pg_advisory_unlock(7061509875526502865)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

=== Dangerous operation detected #strong_migrations ===

New foreign keys are validated by default. This acquires an AccessExclusiveLock,
which is expensive on large tables. Instead, validate it in a separate migration
with a more agreeable RowShareLock.

class CreateReportNotes < ActiveRecord::Migration[5.2]
  def change
    add_foreign_key :report_notes, :reports, column: :report_id, on_delete: :cascade, validate: false
  end
end

class ValidateCreateReportNotes < ActiveRecord::Migration[5.2]
  def change
    validate_foreign_key :report_notes, :reports
  end
end

/vagrant/db/migrate/20180402040909_create_report_notes.rb:11:in `change'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:814:in `exec_migration'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:798:in `block (2 levels) in migrate'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:797:in `block in migrate'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `with_connection'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:796:in `migrate'
/var/lib/gems/2.5.0/gems/chewy-5.0.0/lib/chewy/railtie.rb:37:in `block in migrate'
/var/lib/gems/2.5.0/gems/chewy-5.0.0/lib/chewy/strategy.rb:70:in `wrap'
/var/lib/gems/2.5.0/gems/chewy-5.0.0/lib/chewy.rb:201:in `strategy'
/var/lib/gems/2.5.0/gems/chewy-5.0.0/lib/chewy/railtie.rb:37:in `migrate'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:977:in `migrate'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:1292:in `block in execute_migration_in_transaction'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:1343:in `block in ddl_transaction'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/database_statements.rb:267:in `block in transaction'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/transaction.rb:239:in `block in within_new_transaction'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/transaction.rb:236:in `within_new_transaction'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/database_statements.rb:267:in `transaction'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/transactions.rb:212:in `transaction'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:1343:in `ddl_transaction'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:1291:in `execute_migration_in_transaction'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:1263:in `block in migrate_without_lock'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:1262:in `each'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:1262:in `migrate_without_lock'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:1210:in `block in migrate'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:1363:in `with_advisory_lock'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:1210:in `migrate'
/var/lib/gems/2.5.0/gems/chewy-5.0.0/lib/chewy/railtie.rb:37:in `block in migrate'
/var/lib/gems/2.5.0/gems/chewy-5.0.0/lib/chewy/strategy.rb:70:in `wrap'
/var/lib/gems/2.5.0/gems/chewy-5.0.0/lib/chewy.rb:201:in `strategy'
/var/lib/gems/2.5.0/gems/chewy-5.0.0/lib/chewy/railtie.rb:37:in `migrate'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:1036:in `up'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:1011:in `migrate'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/tasks/database_tasks.rb:172:in `migrate'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/railties/databases.rake:60:in `block (2 levels) in <top (required)>'
/var/lib/gems/2.5.0/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

我尝试删除用于测试和开发的数据库,然后回到第一条消息。(注意:我直接从 psql 中删除,因为 rake 命令也不起作用)

在设置服务器之前没有进行任何迁移foreman start

这又是命令的结果bundle exec rake db:create

$ sudo bundle exec rake db:create
warning: parser/current is loading parser/ruby25, which recognizes
warning: 2.5.5-compliant syntax, but you are running 2.5.1.
warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
(1.3ms)  CREATE DATABASE "social_development" ENCODING = 'unicode'
PG::InsufficientPrivilege: ERROR:  permission denied to create database
: CREATE DATABASE "social_development" ENCODING = 'unicode'
Couldn't create 'social_development' database. Please check your configuration.
rake aborted!
ActiveRecord::NoDatabaseError: FATAL:  role "root" does not exist
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:696:in `rescue in connect'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:691:in `connect'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:223:in `initialize'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:48:in `new'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:48:in `postgresql_connection'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:811:in `new_connection'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:855:in `checkout_new_connection'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:834:in `try_to_checkout_new_connection'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:795:in `acquire_connection'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:523:in `checkout'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:382:in `connection'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:1014:in `retrieve_connection'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_handling.rb:118:in `retrieve_connection'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_handling.rb:90:in `connection'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/tasks/postgresql_database_tasks.rb:12:in `connection'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/tasks/postgresql_database_tasks.rb:21:in `create'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/tasks/database_tasks.rb:119:in `create'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/tasks/database_tasks.rb:139:in `block in create_current'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/tasks/database_tasks.rb:316:in `block in each_current_configuration'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/tasks/database_tasks.rb:313:in `each'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/tasks/database_tasks.rb:313:in `each_current_configuration'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/tasks/database_tasks.rb:138:in `create_current'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/railties/databases.rake:29:in `block (2 levels) in <top (required)>'
/var/lib/gems/2.5.0/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'

Caused by:
PG::ConnectionBad: FATAL:  role "root" does not exist
/var/lib/gems/2.5.0/gems/pg-1.1.4/lib/pg.rb:56:in `initialize'
/var/lib/gems/2.5.0/gems/pg-1.1.4/lib/pg.rb:56:in `new'
/var/lib/gems/2.5.0/gems/pg-1.1.4/lib/pg.rb:56:in `connect'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:692:in `connect'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:223:in `initialize'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:48:in `new'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:48:in `postgresql_connection'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:811:in `new_connection'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:855:in `checkout_new_connection'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:834:in `try_to_checkout_new_connection'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:795:in `acquire_connection'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:523:in `checkout'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:382:in `connection'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:1014:in `retrieve_connection'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_handling.rb:118:in `retrieve_connection'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_handling.rb:90:in `connection'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/tasks/postgresql_database_tasks.rb:12:in `connection'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/tasks/postgresql_database_tasks.rb:21:in `create'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/tasks/database_tasks.rb:119:in `create'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/tasks/database_tasks.rb:139:in `block in create_current'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/tasks/database_tasks.rb:316:in `block in each_current_configuration'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/tasks/database_tasks.rb:313:in `each'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/tasks/database_tasks.rb:313:in `each_current_configuration'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/tasks/database_tasks.rb:138:in `create_current'
/var/lib/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/railties/databases.rake:29:in `block (2 levels) in <top (required)>'
/var/lib/gems/2.5.0/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
Tasks: TOP => db:create
(See full trace by running task with --trace)

我使用的软件版本是:

  • 红宝石 2.5.1p57
  • 导轨 5.2.3
  • 耐嚼的宝石 5.0.0(我猜)
  • Node.js v10.24.1
  • PostgreSQL 10.18

除此之外,我什么都没试过,我不知道如何继续。

4

0 回答 0