[Ruby] Resolve ActiveRecord :: NoDatabaseError when doing rails test (Rails tutorial Chapter 3)

less than 1 minute read

Keep track of any errors that occur as you progress through the rails tutorial.
The hardware uses MacBook Air, and the development environment uses VScode.

Rails Tutorial Chapter 3 3.3.1 First Test

Command to execute

$ rails test

Error that occurs

$ rails test
~abridgement~ FATAL:  database "tutorial_test" does not exist (ActiveRecord::NoDatabaseError)

This is ** no database! The error is **. When you do rails test, you also need to create a database for ** testing. ** **

Solution Generate a database

Therefore, generate a database with the command.

Command to run to generate the database

$ rails db:create

By the way

$ rake db:create

But you can. You can refer to this article for this. What is Rails rake?

This command will generate a database according to the contents of config / database.yml.

Execution result

$ rails db:create

Created database 'app name_development'
Created database 'app name_test'

If you see this, you have successfully generated the database.

At this point, the $ rails test should pass correctly!

If you find it useful, I would be grateful if you could click the ** LGTM button. ** **
Let’s do our best to learn Rails together! : raised_hand_tone1: