🧑‍💻

《Rails》データベース作成時のエラー【オリジナルアプリ作成】

2024/03/17に公開

こんにちは、ミヤビです(^^)

ちょっと前の話ですが、データベース作成時にエラー?メッセージが出て考えたことがあったので記事にしてみました。

データベース作成時

少し前に書いていたデータベースを作成する時の記事はこちら。
https://zenn.dev/d_miyabi/articles/2eebbb1400fe16

単純に、ターミナルで下記コマンドを実行した時にメッセージが出て、スムーズにデータベースが作成されませんでした。

rails db:create

出たメッセージがこちらです。

Ignoring debug-1.7.1 because its extensions are not built. Try: gem pristine debug --version 1.7.1
Ignoring rbs-2.8.2 because its extensions are not built. Try: gem pristine rbs --version 2.8.2
Usage:
  rails new APP_PATH [options]

Options:
            [--skip-namespace]                             # Skip namespace (affects only isolated engines)
                                                           # Default: false
            [--skip-collision-check]                       # Skip collision check
                                                           # Default: false
  -r,       [--ruby=PATH]                                  # Path to the Ruby binary of your choice
                                                           # Default: /Users/masanorisaito/.rbenv/versions/3.2.0/bin/ruby
  -m,       [--template=TEMPLATE]                          # Path to some application template (can be a filesystem path or URL)
  -d,       [--database=DATABASE]                          # Preconfigure for selected database (options: mysql/postgresql/sqlite3/oracle/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc)
                                                           # Default: sqlite3
  -G,       [--skip-git]                                   # Skip .gitignore file
                                                           # Default: false
            [--skip-keeps]                                 # Skip source control .keep files
                                                           # Default: false
  -M,       [--skip-action-mailer]                         # Skip Action Mailer files
                                                           # Default: false
            [--skip-action-mailbox]                        # Skip Action Mailbox gem
                                                           # Default: false
            [--skip-action-text]                           # Skip Action Text gem
                                                           # Default: false
  -O,       [--skip-active-record]                         # Skip Active Record files
                                                           # Default: false
            [--skip-active-job]                            # Skip Active Job
                                                           # Default: false
            [--skip-active-storage]                        # Skip Active Storage files
                                                           # Default: false
  -C,       [--skip-action-cable]                          # Skip Action Cable files
                                                           # Default: false
  -A,       [--skip-asset-pipeline]                        # Indicates when to generate skip asset pipeline
                                                           # Default: false
  -a,       [--asset-pipeline=ASSET_PIPELINE]              # Choose your asset pipeline [options: sprockets (default), propshaft]
                                                           # Default: sprockets
  -J,       [--skip-javascript]                            # Skip JavaScript files
                                                           # Default: false
            [--skip-hotwire]                               # Skip Hotwire integration
                                                           # Default: false
            [--skip-jbuilder]                              # Skip jbuilder gem
                                                           # Default: false
  -T,       [--skip-test]                                  # Skip test files
                                                           # Default: false
            [--skip-system-test]                           # Skip system test files
                                                           # Default: false
            [--skip-bootsnap]                              # Skip bootsnap gem
                                                           # Default: false
            [--dev], [--no-dev], [--skip-dev]              # Set up the application with Gemfile pointing to your Rails checkout
                                                           # Default: false
            [--edge], [--no-edge], [--skip-edge]           # Set up the application with Gemfile pointing to Rails repository
                                                           # Default: false
  --master, [--main], [--no-main], [--skip-main]           # Set up the application with Gemfile pointing to Rails repository main branch
                                                           # Default: false
            [--rc=RC]                                      # Path to file containing extra configuration options for rails command
            [--no-rc]                                      # Skip loading of extra configuration options from .railsrc file
                                                           # Default: false
            [--api], [--no-api], [--skip-api]              # Preconfigure smaller stack for API only apps
                                                           # Default: false
            [--minimal], [--no-minimal], [--skip-minimal]  # Preconfigure a minimal rails app
  -j,       [--javascript=JAVASCRIPT]                      # Choose JavaScript approach [options: importmap (default), webpack, esbuild, rollup]
                                                           # Default: importmap
  -c,       [--css=CSS]                                    # Choose CSS processor [options: tailwind, bootstrap, bulma, postcss, sass] check https://github.com/rails/cssbundling-rails
  -B,       [--skip-bundle]                                # Don't run bundle install
                                                           # Default: false

Runtime options:
  -f, [--force]                                      # Overwrite files that already exist
  -p, [--pretend], [--no-pretend], [--skip-pretend]  # Run but do not make any changes
  -q, [--quiet], [--no-quiet], [--skip-quiet]        # Suppress status output
  -s, [--skip], [--no-skip], [--skip-skip]           # Skip files that already exist

Rails options:
  -h, [--help], [--no-help], [--skip-help]           # Show this help message and quit
  -v, [--version], [--no-version], [--skip-version]  # Show Rails version number and quit

Description:
    The 'rails new' command creates a new Rails application with a default
    directory structure and configuration at the path you specify.

    You can specify extra command-line arguments to be used every time
    'rails new' runs in the .railsrc configuration file in your home directory,
    or in $XDG_CONFIG_HOME/rails/railsrc if XDG_CONFIG_HOME is set.

    Note that the arguments specified in the .railsrc file don't affect the
    defaults values shown above in this help message.

Example:
    rails new ~/Code/Ruby/weblog

    This generates a skeletal Rails installation in ~/Code/Ruby/weblog.

内容を調べてみました。
英語が得意でないのとまだまだ経験値が低くてひとつひとつのメッセージを読み解くのが大変ですね。
要約するとこういうことかな、と思います。

gemの問題

解決策もターミナルのログで提案されていて、gemの問題は下記を実行してgemを再ビルドすれば良さそうです。

gem pristine debug --version 1.7.1
gem pristine rbs --version 2.8.2 

僕の場合は最初から作り直して、raislのバージョンを最新のものにしたら解決したので作成する時のrailsのバージョンとgemのバージョンでこの問題は起きたり起きなかったりするのかもですね。

引数の問題

引数の問題は単純にコマンドを実行した時のディレクトリが違った、です^^;
データベースを作成するときに該当のディレクトリに移動してから「rails db:create」を実行しないといけない、でしたね。
「何のデータベースを作ればいいのか分からない」の状態だったんかな〜、と思います。

意外と最初から「rails new」でアプリを作るって作業は頻度が多くないのかもしれないですね。

エラーの数だけ成長すると思っているので、慌てず焦らず取り組んでいきます。

余談ですが、春が近付くと花粉症に悩まされて集中力低下気味です^^;

より良い人生にしていきましょう♪

Discussion