无法加载`Rails.application.database_configuration`:未知别名:默认 [英] Cannot load `Rails.application.database_configuration`: Unknown alias: default

查看:32
本文介绍了无法加载`Rails.application.database_configuration`:未知别名:默认的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Ruby on Rails 的新手,我猜我的问题的答案很简单,但我找不到.我最近创建了一个项目并使用了rails generate scaffold..."并且一切正常.我想向数据库添加另一列,所以我使用了rails generate migration ...."之后一切都运行良好.在我停止服务器并重新启动它后问题就开始了.现在我收到这个错误Psych::BadAlias无法加载 Rails.application.database_configuration:未知别名:默认

I am new to Ruby on Rails and I am guessing that the answer to my question is pretty simple but I can't find it. I recently created a project and used "rails generate scaffold..." and everything was working fine. I wanted to add another column to the database so I used "rails generate migration ...." Everything worked well after this too. The problem started after I stopped the server and restarted it. Now I get this error Psych::BadAlias Cannot load Rails.application.database_configuration: Unknown alias: default

我发现了这个 请求 ruby​​-on-rails 应用程序给出了 Psych::BadAlias 错误,但我没有看到明确的答案.

I found this Requesting a ruby-on-rails application gives Psych::BadAlias error but I didn't see a definite answer.

这是我的 database.yml 文件的样子...

Here is what my database.yml file looks like...

  #  

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


  test:
    <<: *default
    database: db/development.sqlite3_test

  production:
    <<: *default  
    database: db/development.sqlite3_production 

这是我迁移后生成的文件

Here is the file that genereated after I did the migration

class AddHardwareToComputers < ActiveRecord::Migration
  def change
    add_column :computers, :hardware, :string
  end
end

这是我的 schema.rb

and here is my schema.rb

ActiveRecord::Schema.define(version: 20140723203054) do  

  create_table "computers", force: true do |t|
    t.string   "name"
    t.string   "serial_number"
    t.string   "user"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.string   "hardware" 
  end

end

任何帮助将不胜感激.谢谢.

Any help would be appreciated. Thank you.

推荐答案

我知道这是一个老问题,但我一直在寻找同样的问题,并使用 jvnill 的 + CocoHot 的建议解决了它,并稍作修正.我没有足够的分数来评论,所以我将修改后的解决方案添加为新答案.

I know this is an old question but I was looking for the same issue and got it resolved using jvnill's + CocoHot's suggestion with a small correction. I don't have enough points to comment so I'm adding the amended solution as a new answer.

首先,将&defaults改为&default(单数);其次,由于您使用的是 sqlite3(就像我一样),请将适配器 mysql2 替换为 sqlite3.

First, change &defaults to &default (singular); second, since you are using sqlite3 (as I am), replace the adapter mysql2 with sqlite3.

defaults: &default
  adapter: sqlite3
  encoding: utf8

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

test:
  <<: *default
  database: db/development.sqlite3_test

production:
  <<: *default
  database: db/development.sqlite3_production

这篇关于无法加载`Rails.application.database_configuration`:未知别名:默认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆