Ruby on Rails无法找到" config / databases / sqlite3.yml"

时间:2017-12-04 12:59:35

标签: ruby-on-rails ruby

我在创建一个新的Rails应用程序时遇到了麻烦,以前它工作正常。

使用mysql或postgres并不能解决问题。每种数据库类型的输出都相同。

创建新应用程序时会发出有关sqlite的第一个警告。

rails new myapp --quiet
Initialized empty Git repository in /home/libros/myapp/.git/
Could not find "config/databases/sqlite3.yml" in any of your source paths. Your current source paths are: 
/home/libros/.rvm/gems/ruby-2.4.2/gems/railties-5.1.4/lib/rails/generators/rails/app/templates

然后尝试使用应用程序执行一些基础操作会导致另一个错误。

rails db:create
rails aborted!
Don't know how to build task 'db:create' (see --tasks)
/home/libros/.rvm/gems/ruby-2.4.2/gems/railties-5.1.4/lib/rails/commands/rake/rake_command.rb:21:in `block in perform'
/home/libros/.rvm/gems/ruby-2.4.2/gems/railties-5.1.4/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/home/libros/.rvm/gems/ruby-2.4.2/gems/railties-5.1.4/lib/rails/command.rb:46:in `invoke'
/home/libros/.rvm/gems/ruby-2.4.2/gems/railties-5.1.4/lib/rails/commands.rb:16:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
(See full trace by running task with --trace)

1 个答案:

答案 0 :(得分:0)

首先卸载sqllite3并尝试安装它 试。

<强>反安装 sudo apt-get remove --auto-remove sqlite3 sudo apt-get purge --auto-remove sqlite3

安装 sudo add-apt-repository ppa:jonathonf / backports sudo apt-get update&amp;&amp; sudo apt-get install sqlite3

在config文件夹

中的database.yml中创建一个文件

并粘贴代码

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
#
default: &default
  adapter: sqlite3
  pool: 5
  timeout: 5000

development:
  <<: *default
  database: db/development.sqlite3

# 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

保存并重新启动应用程序。