[英]Getting Active records not found error when trying to configure database using mysql 5.7.1 with Rails 5 in windows
I am new to RAILS and RUBY. 我是RAILS和RUBY的新手。 I am trying to create a demo project to practice.
我正在尝试创建一个演示项目进行练习。 When I was trying to configure my mysql database with RAILS, I got following error:
当我尝试使用RAILS配置我的mysql数据库时,出现以下错误:
C:\Sites\simple_cms>rake db:schema:dump
rake aborted!
ActiveRecord::AdapterNotSpecified: 'development' database is not configured.
Available: ["default", "adapter", "pool", "timeout", "database", "username",
"password", "host"]
Tasks: TOP => db:schema:dump => db:load_config
(See full trace by running task with --trace)
Below is my database.yml file content 以下是我的database.yml文件内容
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: mysql
pool: 5
timeout: 5000
database: simple_cms_development
username: dumdum
password: dumdum
host: localhost
development:
<<: *default
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3
I tried searching online but got no clear help. 我尝试在线搜索,但没有明确的帮助。 I am running RAILS on WINDOWS 10
我在WINDOWS 10上运行RAILS
before using rake db:schema:dump you have to create the database and then later you create tables, 在使用rake db:schema:dump之前,您必须先创建数据库,然后再创建表,
to create database for your project 为您的项目创建数据库
rake db:create
to create tables 创建表
rake db:migrate
after this you may be can check table schema using rake db:schema:dump 之后,您可以使用rake db:schema:dump检查表架构
I felt like you didn't indent your yaml file properly and therefore you the development
cannot read the settings of default
. 我觉得您没有正确缩进yaml文件,因此您的
development
无法读取default
的设置。 Please try to indent it properly. 请尝试正确缩进。
Another thing that I have noticed is that your port number is not set. 我注意到的另一件事是您的端口号未设置。 I have updated the settings as follow by referring to Correct MySQL configuration for Ruby on Rails Database.yml file
通过参考Ruby on Rails Database.yml文件的正确MySQL配置,我更新了以下设置。
Please try the following and let me know: 请尝试以下操作,并让我知道:
default: &default
adapter: mysql2
timeout: 5000
username: dumdum
password: dumdum
host: localhost
port: 3306
development:
<<: *default
database: simple_cms_development
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: simple_cms_test
production:
<<: *default
database: simple_cms_production
Hope this helps. 希望这可以帮助。
Try below code: 试试下面的代码:
gem 'mysql2'
default: &default
adapter: mysql2
pool: 5
timeout: 5000
username: username #your mysql username
password: password #your mysql password
development:
<<: *default
database: simple_cms_development
test:
<<: *default
database: simple_cms_test
production:
<<: *default
database: simple_cms_production
Then run command: 然后运行命令:
bundle
rake db:create
rake db:migrate
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.