尝试在生产中创建模型实例时获取UnknownAttributeError
。在本地工作正常,但在Heroku上没有。
ActiveRecord::UnknownAttributeError: unknown attribute 'team_id' for Membership
用户注册后,他们所做的第一件事就是创建一个团队。如果团队保存,那么团队#create使他们成为该团队的成员。
Membership.create(user_id: current_user.id, team_id: @team.id )
小组has_many :users, through: :memberships
和用户has_many :teams, through: :memberships
。
class Membership < ActiveRecord::Base
belongs_to :user
belongs_to :team
validates :user_id, presence: true
validates :team_id, presence: true
end
甚至看起来像team_id
在Heroku的Membership
表上,所以我很困惑......
SQL (0.9ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) [["version", "20150502213611"]]
(1.3ms) COMMIT
Migrating to CreateMemberships (20150502215929)
(0.5ms) BEGIN
== 20150502215929 CreateMemberships: migrating ================================
-- create_table(:memberships)
(7.4ms) CREATE TABLE "memberships" ("id" serial primary key, "user_id" integer, "team_id" integer, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
-> 0.0079s
== 20150502215929 CreateMemberships: migrated (0.0080s) =======================
同样,本地没有问题,仅在Heroku上。
运行Rails 4.2.1
答案 0 :(得分:1)
尽管我的模型中明显存在属性,但我有相同的未知属性错误。据我所知,heroku结束时出现了错误。我修好了:
heroku restart
答案 1 :(得分:0)
这神奇地在一分钟前开始工作。不知道为什么。