Resolve ActiveRecord :: NoDatabaseError on rails6

The hardware uses MacBook Air, and the development environment uses VScode.

This is a solution for the error that accompanies the previous article (Making the database PostgreSQL with rails new) (

: small_red_triangle_down: Previous content

Specify PostgreSQL as database

$ rails _5.1.6_new app name--database=postgresql

Do this in rails 6

$ rails server

When you start the server with and access [localhost: 3000](http: // localhost: 3000 /), I get the error ** ActiveRecord :: NoDatabaseError **.

This is an error caused by the ** database not existing. ** **

Solution: Create a database

How to do it automatically

First, change to the directory created by rails new.

$cd created directory


$ rails db:create

To generate the database. The database will be automatically generated according to the contents of config / database.yml.

How to do it manually

First, change to the directory created by rails new.

$cd created directory

 > Next, rewrite config / database.yml.

>```:config/database.before changing yml

  <<: *default
  database:app name_development



development: <<: *default database:app name_db host: localhost encoding: utf8 reconnect: false username:My username


 > * Since database: is the database name, change development to db for easy understanding.
 Others (hots, encoding, recconect, username) can be solved without adding them, but it is recommended to add them.

 > ** Next, launch SQL. ** **

$ psql -h localhost -p 5432 -U your username-d postgres

>psql (12.3)
Type "help" for help.


About commands around here It is described in detail in.

($ psql -h localhost -d postgres ← This alone solved the problem.)

Run this command and you will be able to enter SQL statements. I will write the SQL statement to create the database here.


#### **`After input`**

postgres=#create database app name_db;

Here, ** app name \ _db is the database: app name \ _db specified in config / database.yml first. ** **

postgres=#create database app name_db; CREATE DATABASE postgres=# \q

 You can exit by typing \ q at the end.

 Now start the server again with $ rails server and try accessing localhost: 3000. The error should have been resolved.

# I solved it safely!
 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:

Recommended Posts

Resolve ActiveRecord :: NoDatabaseError on rails6
Resolve ActiveRecord :: NoDatabaseError when doing rails test (Rails tutorial Chapter 3)
[Rails] ActiveRecord
Tailwind on Rails
Launch Rails on EC2
Test run on rails
Deploy RAILS on EC2
Ruby on Rails Elementary
Ruby on Rails basics
Yay! I'm on Rails!
[Rails] ActiveRecord :: Attributes :: ClassMethods
Ruby On Rails Association
Ruby on rails learning record -2020.10.03
Portfolio creation Ruby on Rails
Install Sidekiq pro on Rails
Ruby on rails learning record -2020.10.04
[Ruby on Rails] Debug (binding.pry)
Ruby on rails learning record -2020.10.05
Ruby on rails learning record -2020.10.09
Ruby on Rails config configuration
Ruby on Rails basic learning ①
[Ruby on Rails] about has_secure_password
Ruby on rails learning record-2020.10.07 ②
Yay! I'm on Rails! Repetition
Install Rails on macOS Catalina
Commentary on partial! --Ruby on Rails
Post a video on rails
Ruby on rails learning record-2020.10.07 ①
Cancel Ruby on Rails migration
Ruby on rails learning record -2020.10.06
Ruby on Rails validation summary
Ruby on Rails Basic Memorandum
Ruby on Rails Overview (Beginner Summary)
How to deploy jQuery on Rails
[Ruby on Rails] Read try (: [],: key)
[Ruby on Rails] yarn install --check-files
Ruby on Rails variable, constant summary
Installing Ruby + Rails on Ubuntu 18.04 (rbenv)
[Ruby on Rails] Introduced paging function
Basic knowledge of Ruby on Rails
Progate Ruby on Rails5 Looking Back
How to use Ruby on Rails
How to deploy Bootstrap on Rails
[Ruby on Rails] Add / Remove Columns
Ruby on Rails Japanese-English support i18n
(Ruby on Rails6) "Erase" posted content
[Ruby on Rails] CSV output function
Ruby on Rails 6.0 environment construction memo
[Ruby on Rails] What is Bcrypt?
Launch Rails on EC2 (manual deployment)
Rails on Tiles (how to write)
Rails on Docker environment construction procedure
[Ruby on Rails] Confirmation page creation
[Today's stack # 1] Until on rails on cloud9
Ruby On Rails devise routing conflict
[Ruby on Rails] Comment function implementation
[Ruby on Rails] DM, chat function
Deploy Rails on Docker to heroku
[Ruby on Rails] Convenient helper method
Check the root on the Rails browser
Deploy your Rails app on Heroku