I started creating web services today because I wanted to put the ideas I came up with into shape. Immediately, I was addicted to the error, so I will leave it as a memorandum.
environment
Rails : 6.0.3.2
ruby : 2.6.3
I am creating a user login screen with devise. An error occurred with the following command.
Terminal
$ rake db:migrate
rake aborted!
ActiveRecord::StatementInvalid: Mysql2::Error: No database selected
Apparently, the database has not been selected. If you check database.yml, ...
database.yml
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: <%= ENV['DATABASE_DEV_USER'] %>
password: <%= ENV['DATABASE_DEV_PASSWORD'] %>
host: <%= ENV['DATABASE_DEV_HOST'] %>
development:
<<: *default
database: <%= ENV['DATABASE_DEV_NAME'] %>
test:
<<: *default
database: <%= ENV['DATABASE_DEV_NAME'] %>
production:
<<: *default
database: <%= ENV['DATABASE_DEV_NAME'] %>
database
is specified by an environment variable,
It seems that an error occurred because there is nothing in the .env file.
Write database
in database.yml directly instead of environment variables.
database.yml
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: <%= ENV['DATABASE_DEV_USER'] %>
password: <%= ENV['DATABASE_DEV_PASSWORD'] %>
host: <%= ENV['DATABASE_DEV_HOST'] %>
development:
<<: *default
database: development
test:
<<: *default
database: test
production:
<<: *default
database: production
Run rake db: migrate
again.
Terminal
rake aborted!
ActiveRecord::NoDatabaseError: Unknown database 'development'
Is displayed. Apparently the database cannot be found.
Create database with rails & migrate (MySQL) I referred to the above article.
###Database creation
rake db:create:all
###migration
rake db:migrate
This completes successfully.
Recommended Posts