Question: Why I get `ActiveRecord::NoDatabaseError: Unknown database` error when trying to use numbers and underline in database name?

Question

Why I get `ActiveRecord::NoDatabaseError: Unknown database` error when trying to use numbers and underline in database name?

Answers 1
Added at 2016-12-22 10:12
Tags
Question

I am using ruby-2.2.4, Rails 4.2.5 and MySQL 5.7.16 with gem mysql2 in my Ruby on Rails application. I have created database with name 123_4 and set database name in /config/database.yml.

Why I am getting error ActiveRecord::NoDatabaseError: Unknown database '1234' when trying rake db:migrate?

If I try to run rake db:create database with name 1234 will be created.

If I use 123_abc4 for database name everything is fine.

my database.yml content:

production: 
   adapter: mysql2 
   database: 123_4 
   host: localhost 
   username: user 
   password: "pass" 
   encoding: utf8
Answers to

Why I get `ActiveRecord::NoDatabaseError: Unknown database` error when trying to use numbers and underline in database name?

nr: #1 dodano: 2016-12-22 11:12

Identifiers may begin with a digit but unless quoted may not consist solely of digits.

MySQL Schema Object Name

So you can use 123_abc4 because it contains letters.

If it only includes number, you will need to quote it: '123_4'

Source Show
◀ Wstecz