ruby-on-rails - (ActiveModel::UnknownAttributeError) 在 heroku 中,但是在本地主机和 Heroku 本地工作
问题描述
我正在构建一个超级基本的格斗游戏词典。该应用程序可以在本地主机上运行,并且在 Heroku 本地上没有问题。
这是我的模型
class Vocabulary < ApplicationRecord
validates :word, presence:true
validates :definition, presence:true
has_many :users, :through => :favorites
end
这是我的架构
create_table "vocabularies", force: :cascade do |t|
t.string "word", null: false
t.string "definition", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
这是我在运行 heroku run rails 控制台时收到的错误
/app/vendor/bundle/ruby/2.4.0/gems/activemodel-5.2.3/lib/active_model/attribute_assignment.rb:53:in `_assign_attribute': unknown attribute 'Word' for Vocabulary. (ActiveModel::UnknownAttributeError)
我试过:Heroku rake db:migrate,重置我的数据库,从 Heroku 删除应用程序并重建,哭了很多
我完全没有想法,所以任何帮助将不胜感激。
谢谢!
解决方案
所以我的应用程序遇到了完全相同的问题。我在模型中添加了一个新字段,由于某种原因,在推动更改时,heroku 没有选择该字段并且显示未知属性错误。但是,当我检查 heroku 控制台时,我可以看到它确实在那里。尽管如此,这是我解决它的步骤。
首先重置heroku中的数据库
heroku rake pg:reset
(假设您使用的是pg)然后,再次运行迁移... -
heroku rake db:migrate
(在运行此迁移时,它应该注销它实际上正在使用您要添加的字段运行该特定迁移)。如果您有种子数据,那么... -
heroku rake db:seed
推荐阅读
- python-3.x - cv2.VideoWriter 不工作(Windows 10)
- php - Apache / WSGI 和 PHP 突然无法连接到 MSSQL 服务器——站点宕机
- dapper - 使用 Split-on 和 Query Multiple 在 dapper 中映射多个对象
- swift3 - 在 userdefaults 中存储服务器响应时....我收到错误
- node.js - REG:将 NODEJS 连接到 ORACLEDB 时没有结果
- css - 移动设备上不显示子菜单箭头
- node.js - jdbc节点包安装失败
- sql - 如何将 2 行转换为 tsql 中的列?
- php - Laravel 5.7 雄辩
- bash - 如何执行打开交互式并在容器内继续的脚本