我是 Ruby on Rails 的新手,我猜我的问题的答案非常简单,但我找不到它。我最近创建了一个项目并使用“railsgeneratescaffold...”,一切工作正常。我想向数据库添加另一列,因此我使用了“railsgeneratemigration....”此后一切都运行良好。我停止服务器并重新启动后出现问题。现在我得到这个错误
心理::BadAlias
无法加载Rails.application.database_configuration
:未知别名:默认
我找到了这个请求 ruby-on-rails 应用程序会出现 Psych::BadAlias 错误 https://stackoverflow.com/questions/23847007/requesting-a-ruby-on-rails-application-gives-psychbadalias-error但我没有看到明确的答案。
这是我的 database.yml 文件的样子......
#
<<: *default
database: db/development.sqlite3
test:
<<: *default
database: db/development.sqlite3_test
production:
<<: *default
database: db/development.sqlite3_production
这是我迁移后生成的文件
class AddHardwareToComputers < ActiveRecord::Migration
def change
add_column :computers, :hardware, :string
end
end
这是我的 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
任何帮助,将不胜感激。谢谢。
我知道这是一个老问题,但我一直在寻找同样的问题,并使用 jvnill 的 + CocoHot 的建议和一个小修正解决了它。我没有足够的观点来发表评论,因此我将修改后的解决方案添加为新答案。
首先,改变&defaults
to &default
(单数);其次,由于您使用的是sqlite3(就像我一样),请更换适配器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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)