I got something like this when i hit rake db:migrate Im using figaro in my app, its my first time with this gem any mysql so I cant get what excatly is wrong. Thanks in advance :)
Mysql2::Error: No database selected: CREATE TABLE
schema_migrations(versionvarchar(255) PRIMARY KEY) ENGINE=InnoDB
database.yml
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: <%= ENV["DB_USER"] %>
password: <%= ENV["DB_PASSWORD"] %>
development:
<<: *default
database: <%= ENV["DB_DATABASE_DEV"] %>
test:
<<: *default
database: <%= ENV["DB_DATABSE_TEST"] %>
production:
<<: *default
database: <%= ENV['DB_DATABASE_PRODUCTION'] %>
application.yml
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: root
password: password
development:
<<: *default
database: dev
test:
<<: *default
database: test_db
I don't have enough point to ask in comment, but it seems you're trying to run migration without creating a schema first.
Run
rails db:createto create the schema first. For example, if you don't have the a database named "dev" in your MySQL, this command will do so.To set specific environment
Then you run can
rails db:migrate.To destroy a schema if you need one:
You're Using ENV
Though it might not be related, have you set up your ENV properly before running the command?
For Windows, you can add those, for example, DB_USER to
system environmentJust press Start and type
system environment>>Environment Variables...>>New...Note: You might have to restart your system for the environment to work.
Or if you don't have time, simply in your terminal you're running rails s:
The same steps for Linux, but I don't know the specific command. Some prefer to use .env file.