Reputation: 285
Getting an UnknownAttributeError
when trying to create a model instance in production. Works fine locally, but not on Heroku.
ActiveRecord::UnknownAttributeError: unknown attribute 'team_id' for Membership
After a user signs up, the first thing they do is create a team. If the team saves, then teams#create makes them a member of that team.
Membership.create(user_id: current_user.id, team_id: @team.id )
Team has_many :users, through: :memberships
and User 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
Even looks like team_id
is on the Membership
table on Heroku, so I am very confused...
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) =======================
Again, no problems locally, only on Heroku.
Running Rails 4.2.1
Upvotes: 3
Views: 132
Reputation: 52328
I had the same unknownattribute error despite the attribute clearly existing in my model. As far as I can tell it's an error from heroku's end. I fixed it with:
heroku restart
Upvotes: 2