質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

解決済

1回答

671閲覧

[Rails][SyntaxError]$ rails db:create が出来ません。

uk_63

総合スコア29

Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2018/11/12 13:45

編集2018/11/13 00:55

#前提

  • macOS 10.14.1
  • テキストエディタはAtomを使用。
  • rails db:create が出来なかった。
  • railsuserという作業ユーザーを作成。権限付与済み。
  • rails new SAMPLE -d mysql --api  このコマンドを実行済み。

#エラーメッセージ

YAML syntax error occurred while parsing /Users/--私の名前なので伏せます--/Develop/SAMPLE/config/database.yml. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Error: (<unknown>): found character that cannot start any token while scanning for the next token at line 17 column 13 /Library/Ruby/Gems/2.3.0/gems/railties-5.2.1/lib/rails/application/configuration.rb:190:in `rescue in database_configuration' /Library/Ruby/Gems/2.3.0/gems/railties-5.2.1/lib/rails/application/configuration.rb:165:in `database_configuration' /Library/Ruby/Gems/2.3.0/gems/activerecord-5.2.1/lib/active_record/railtie.rb:39:in `block (3 levels) in <class:Railtie>' /Library/Ruby/Gems/2.3.0/gems/railties-5.2.1/lib/rails/commands/rake/rake_command.rb:23:in `block in perform' /Library/Ruby/Gems/2.3.0/gems/railties-5.2.1/lib/rails/commands/rake/rake_command.rb:20:in `perform' /Library/Ruby/Gems/2.3.0/gems/railties-5.2.1/lib/rails/command.rb:48:in `invoke' /Library/Ruby/Gems/2.3.0/gems/railties-5.2.1/lib/rails/commands.rb:18:in `<main>' /Library/Ruby/Gems/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require' /Library/Ruby/Gems/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi' /Library/Ruby/Gems/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register' /Library/Ruby/Gems/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi' /Library/Ruby/Gems/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require' /Library/Ruby/Gems/2.3.0/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:287:in `block in require' /Library/Ruby/Gems/2.3.0/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:253:in `load_dependency' /Library/Ruby/Gems/2.3.0/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:287:in `require' bin/rails:4:in `<main>' Caused by: Psych::SyntaxError: (<unknown>): found character that cannot start any token while scanning for the next token at line 17 column 13 /Library/Ruby/Gems/2.3.0/gems/railties-5.2.1/lib/rails/application/configuration.rb:172:in `database_configuration' /Library/Ruby/Gems/2.3.0/gems/activerecord-5.2.1/lib/active_record/railtie.rb:39:in `block (3 levels) in <class:Railtie>' /Library/Ruby/Gems/2.3.0/gems/railties-5.2.1/lib/rails/commands/rake/rake_command.rb:23:in `block in perform' /Library/Ruby/Gems/2.3.0/gems/railties-5.2.1/lib/rails/commands/rake/rake_command.rb:20:in `perform' /Library/Ruby/Gems/2.3.0/gems/railties-5.2.1/lib/rails/command.rb:48:in `invoke' /Library/Ruby/Gems/2.3.0/gems/railties-5.2.1/lib/rails/commands.rb:18:in `<main>' /Library/Ruby/Gems/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require' /Library/Ruby/Gems/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi' /Library/Ruby/Gems/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register' /Library/Ruby/Gems/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi' /Library/Ruby/Gems/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require' /Library/Ruby/Gems/2.3.0/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:287:in `block in require' /Library/Ruby/Gems/2.3.0/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:253:in `load_dependency' /Library/Ruby/Gems/2.3.0/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:287:in `require' bin/rails:4:in `<main>' Tasks: TOP => db:create => db:load_config (See full trace by running task with --trace)

上記のエラーが発生しました。

#ファイルの共有
database.yml

# MySQL. Versions 5.1.10 and up are supported. # # Install the MySQL driver # gem install mysql2 # # Ensure the MySQL gem is defined in your Gemfile # gem 'mysql2' # # And be sure to use new-style password hashing: # https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html # default: &default adapter: mysql2 encoding: utf8 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> username: railsuser password: --伏せます-- socket: /tmp/mysql.sock development: <<: *default database: SAMPLE_development # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: <<: *default database: SAMPLE_test # As with config/secrets.yml, you never want to store sensitive information, # like your database password, in your source code. If your source code is # ever seen by anyone, they now have access to your database. # # Instead, provide the password as a unix environment variable when you boot # the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database # for a full rundown on how to provide these environment variables in a # production deployment. # # On Heroku and other platform providers, you may have a full connection URL # available as an environment variable. For example: # # DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase" # # You can use this database configuration with: # # production: # url: <%= ENV['DATABASE_URL'] %> # production: <<: *default database: SAMPLE_production username: railsuser password: <%= ENV['SAMPLE_DATABASE_PASSWORD'] %>

#試したこと
エラーメッセージからdatabase.ymlにはタブの使用が認められていないとのことだったので、スペースを使用しました。しかし、同じエラーメッセージが出ます。

found character that cannot start any token while scanning for the next token at line 17 column 13

#1つ目の質問
17行目の13列目にタブの使用が発見されているということですよね?
しかし、該当箇所(database.yml のpassword入力欄)にタブは使わずにスペースを使っています。
なぜこのエラーがでるのかわからないです。

Atomのインデントの設定でもタブが入らないように、タブを入力してもスペースが入るように設定しています。

#2つ目の質問
RailsとMYSQLの連携方法は、僕の認識では、
$ rails new NAME -d mysqlを実行。
database.yml ファイル内に下記を設定。

username: 権限を持った作業ユーザ名の記入 password: 作業ユーザへのログインパス

③ 下記コマンドの実行

$ rails db:create database.ymlの内容でデータベースを作成 $ rails db:migrate  未実行のマイグレーションファイルを全て実行する

以上の3つの工程を踏めば完成という認識で合ってますでしょうか??

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

#解決法
パスワードの文頭に**@**を使用していたために起こった構文エラーでした。
"" (ダブルクォーテーション)で囲うと問題なく下記コマンドを実行出来ました。

rails db:create rails db:migrate

#学び
YMALにはタブの使用が禁止されているなど構文が厳しそうなので、学んでいきたいです。

投稿2018/11/13 01:08

uk_63

総合スコア29

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問