docker-compose で railsアプリのコンテナとDBのコンテナを連携させようと試みています。
コンテナを起動して、ポートから接続を確認したところ、データベース関連のエラーを確認しました。
エラー文 Migrations are pending. To resolve this issue, run: rails db:migrate RAILS_ENV=development
migrationをしろとのことなので、migrationしようとしましたが、
DEPRECATION WARNING: Single arity template handlers are deprecated. Template handlers must now accept two parameters, the view object and the source for the view object. Change: >> Coffee::Rails::TemplateHandler.call(template) To: >> Coffee::Rails::TemplateHandler.call(template, source) (called from <top (required)> at /myproject/rakefile:6) rake aborted! ActiveRecord::StatementInvalid: Mysql2::Error: No database selected /usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:131:in `_query' /usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:131:in `block in query' /usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:130:in `handle_interrupt' /usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:130:in `query' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:202:in `block (2 levels) in execute' /usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads' /usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares' /usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:201:in `block in execute' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_adapter.rb:718:in `block (2 levels) in log' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_adapter.rb:717:in `block in log' /usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/notifications/instrumenter.rb:24:in `instrument' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_adapter.rb:708:in `log' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:200:in `execute' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/mysql/database_statements.rb:41:in `execute' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:315:in `create_table' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/mysql/schema_statements.rb:81:in `create_table' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/schema_migration.rb:33:in `create_table' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1206:in `initialize' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1061:in `new' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1061:in `up' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1036:in `migrate' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/tasks/database_tasks.rb:238:in `migrate' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/railties/databases.rake:86:in `block (3 levels) in <top (required)>' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/railties/databases.rake:84:in `each' /usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/railties/databases.rake:84:in `block (2 levels) in <top (required)>' /usr/local/bundle/gems/rake-13.0.1/exe/rake:27:in `<top (required)>'
Mysql2::Error: No database selected というエラーがでてしまい、migrationができません。
database.yml default: &default adapter: mysql2 encoding: utf8 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> username: root password: password host: db development: <<: *default
docker-compose.yml version: '3' services: db: image: mysql:5.6 environment: MYSQL_DATABASE: root MYSQL_ROOT_PASSWORD: password volumes: - mysql-data:/var/lib/mysql ports: - "4306:3306" app: tty: true stdin_open: true build: . command: bundle exec rails s -p 3000 -b '0.0.0.0' ports: - "0.0.0.0:3000:3000" volumes: - .:/myproject - bundle:/usr/local/bundle links: - db volumes: mysql-data: bundle:
おそらくDB関連の記述で間違えているのだと思いますが、色々試行錯誤しましたが解決できません。
どなたか、解決方法が分かる方、いらっしゃいませんか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/02/26 08:33