尝试 rake db:migrate 时未在 Rails 项目中选择数据库
使用 Rails 应用程序,遇到某种奇怪的数据库/rake 问题。
当我执行时:
rake db:migrate
我收到以下错误:
Mysql2::Error: No database selected: SHOW TABLES
(See full trace by running task with --trace)
跟踪没有透露太多有用的信息。可以在这里看到: http://pastebin.com/WdsguudC
配置文件看起来是正确的,用户正在获取登录,否则我会收到某种访问错误。数据库存在,用户有正确的权限,我可以手动访问和操作它。我已经做了很多谷歌搜索,但没有发现任何有用的东西。不确定是否需要提供任何其他代码,因为这似乎是相当低级别的问题。
Working with a rails app, having some manner of weird database / rake issues.
When I execute:
rake db:migrate
I am getting the following error:
Mysql2::Error: No database selected: SHOW TABLES
(See full trace by running task with --trace)
The trace isn't revealing much useful information. Can be seen here: http://pastebin.com/WdsguudC
The config file looks right, and the user is getting logged in, or I would have gotten some kind of access error. The database exists, the user has correct permission, and I can access and manipulate it manually. I have done a bunch of googling, and haven't found anything helpful. Not sure if there is any other code that needs provided, because this seems like fairly low level problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
毕竟这是 yaml 中的间距问题。
after all that it was a spacing issue in the yaml.
请注意,ruby 在最近的 1.9.2 版本中交换了其 YAML 解析器。
这也可能会导致此问题。
为了切换回旧的 YAML 解析器 syck,请在 boot.rb 中使用:
Note that ruby has exchanged its YAML parser in a recent 1.9.2 version.
This might also cause this problem.
In order to switch back to the old YAML parser syck, use this in boot.rb:
嗯,这是我们初学者的常见问题。这个问题是在您在 Rails 中创建新项目时出现的。假设有一个示例,
在密码字段中添加密码,如下所示,这是您用来保护 mysql 的密码。
另外,在名称前添加井号标记 (#) 注释掉数据库,如下所示。
You have to see the Ruby on Rails 欢迎页面。
创建数据库。
问题消息表明未选择数据库。这是因为我没有创建一个。当您使用 MySQL 时,您必须创建一个,因此:
注意:此示例适用于名为 toy 的项目和用户我想授予的权限是mark,我要提供的密码是45mark。下面您将看到我在哪里应用这些元素。请记住在声明的每个部分应用您自己的元素。
为此项目创建并用户
之前添加的井号标签 (#)
- 另外,删除在保存
Done!!
我希望这有帮助。快乐编码!!
谢谢
Well, it is a common issue for us beginners. This issue comes from the moment when you create your new project in rails. Let’s say to have an example
Add a password in the password field as shown below, this is the password you use to secure mysql.
Also, comment out the database adding a hash tag (#)before the name as shown below
You have to see the Ruby on Rails welcome page..
Create a DATABASE.
The issue message is saying that not DATABASE is selected. It is because I didn’t create one. When you work with MySQL you have to create one, so:
Note: This example works wit a project called toy and the user I wanted to grant privileges is mark and the password I’ll give is 45mark. Below you will see where I apply these elements. Remember to apply your own elements on each part of the statement.
Create and user for this project
- Also, REMOVE the hash tag (#) added before
Save it.
Done!!
I hope this helps. Happy coding!!
Thanks
我对 ruby 1.9.2-p180 遇到了同样的问题,升级到 p290 并且它可以工作
I had the same issue with ruby 1.9.2-p180 , upgraded to p290 and it works
只需重启服务器即可;在命令行中:
按 Ctrl + C
执行:
Just restart the server; in the command line:
Press Ctrl + C
execute:
当我输入
rake db:schema:dump
时,我遇到了类似的错误,结果我只需注释掉我的 yaml 文件中的所有数据库,除了我的development
数据库。I had a similar error when i typed
rake db:schema:dump
and it turns out that I just have to comment out all the databases on my yaml file except mydevelopment
one.尝试一下这个。
安装它以查看您是否确实创建了表。打开 db 文件夹中的“development.sqlite3”
http://sqlitebrowser.org/
Give a try to this.
Install this to see if you have actually created a table or not. Open the "development.sqlite3" in db folder
http://sqlitebrowser.org/
这是一个简单的错误,检查整个database.yml文件,看看默认描述在哪里给出,如果没有给出数据库名称,那么看看下面,还会给出另一个开发名称,其中数据库的配置是使用检查,给你的其中数据库名称
Its a simple error checkout the entire database.yml file and see that where is default decription is given database name is given or not if not then look below it there will another development name is also given where configuration of database is use check that give your database name in it
一个潜在原因是定义了
DATABASE_URL
环境变量。如果您得到与上述 url 类似的输出(即数据库名称不存在),那么您可能需要将数据库名称添加到字符串中或取消设置环境变量。
如果您
取消设置
var,您可能想在database.yml
中指定数据库详细信息。One potential cause is that there is a
DATABASE_URL
environment variable defined.If you get a similar output to the above url (i.e., the database name is not present), then you might want to add the database name to the string or unset the env var.
If you
unset
the var, you probably want to specify the database details indatabase.yml
instead.