Database is not selected in rails project when trying db: migrate rake

Working with a rails application that has some strange database problems / rake.

When I execute:

rake db:migrate 

I get the following error:

 Mysql2::Error: No database selected: SHOW TABLES (See full trace by running task with --trace) 

The footprint does not show a lot of useful information. Here you can see: http://pastebin.com/WdsguudC

The configuration file looks right and the user logs in, or I would get some access error. The database exists, the user has the correct permission, and I can access and manipulate it manually. I did a bunch of search queries and didn't find anything useful. Not sure if there is any other code you need because it seems like a low level problem.

+8
ruby-on-rails ruby-on-rails-3 migration mysql2 rake
source share
8 answers

after all it was a problem with the interval in yaml.

+12
source share

Note that ruby ​​traded its YAML parser in the latest version 1.9.2.

It may also cause this problem.

To revert to the old YAML syntax, use this in boot.rb :

 require 'yaml' YAML::ENGINE.yamler= 'syck' 
+9
source share

I had the same problem with ruby ​​1.9.2-p180, upgraded to p290, and it works

+2
source share

Just restart the server; on the command line:

  • Press Ctrl + C

  • execute:

     rails s 
+1
source share

Well, this is a common problem for us beginners. This problem has arisen since the creation of a new project in rails. Suppose there is an example

  $ rails new toy –d mysql 
  • After you run the package and start your server, most likely you will have an error. To fix this, you need to go to database.yml and change the following:

Add the password in the password field as shown below, this is the password that you use to protect mysql.

 default: & default
   adapter: mysql2
   encoding: utf8
   pool: 5
   username: root
   password: mypassword
   socket: /tmp/mysql.sock 

Also, comment out the database by adding a hash tag (#) in front of the name, as shown below.

 development:
  : * default
    database: #toy_development
  • Then restart your command line and go to the root of your application and type:
  $ rails s 

You need to see the Ruby on Rails welcome page.

  • After that you need to create a database.

Create a database.

The error message says that the database is not selected. This is because I did not create it. When you are working with MySQL, you should create it like this:

  • Go to the root of my application and type:
  $ mysql –u root –p 
 $ Passwor: mypassword (Enter your password, this is the one you entered to secure MySQL)

Note. In this example, a project called toy works, and the user I wanted to grant privileges to is mark , and the password I give is 45mark . Below you will see where I apply these elements. Remember to apply your own elements in each part of the manual.

Creation and use of this project

  • As soon as you enter, you will see a pointer ( mysql> ), so enter after it:
  mysql> GRANT ALL PRIVILEGES ON toy_development. * TO 'mark' @ 'localhost' IDENTIFIED BY '45mark'; 
  • Then enter:
  mysql> exit; 
  • Make sure it works by typing:
  $ mysql –u mark –p toy_development
 Enter password: 45mark (You enter the one you gave) 
  • Open the database.yml file and configure the necessary and correct as necessary. In my case, I will mark the username and password for 45mark
 default: & default
   adapter: mysql2
   encoding: utf8
   pool: 5
   username: mark
   password: 45mark
   socket: /tmp/mysql.sock


- In addition, REMOVE hash tag (#) added to

  development:
   : * default
      database: toy_development 

Save it.

  • Go to the root of the application and type
  $ rake db: schema: dump 

Done !!

Hope this helps. Happy coding!

thanks

+1
source share

I had a similar error when I typed rake db:schema:dump , and it turned out that I just needed to comment out all the databases in my yaml file, except for my development .

0
source share

Try it.

 rake db:test:prepare 

Set this to see if you really created the table or not. Open development.sqlite3 "in the db folder

http://sqlitebrowser.org/

0
source share

Its a simple error checking of the entire database.yml file and viewing where the default definition is indicated, the database name is specified, or not, if not, look below, there will be a different development name, where the database configuration is checked for use which give the name of your database in it

 default: &default adapter: mysql2 encoding: utf8 pool: 5 username: root password: 12345 host: localhost development: <<: *default database: db_name 
0
source share

All Articles