Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7688581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:57:16+00:00 2026-05-31T19:57:16+00:00

I have a Rails 3.1 app with a User model and a Venue model.

  • 0

I have a Rails 3.1 app with a User model and a Venue model. These two models have a HABTM relationship – A user may manage many venues and a venue may be managed by many users.

I’d like users to be able to select a default venue so I’m trying to add a default_venue_id attribute to User with the following migration:

class AddDefaultVenueIdToUser < ActiveRecord::Migration
  def self.up
    add_column :users, :default_venue_id, :integer
  end

  def self.down
    remove_column :users, :default_venue_id
  end
end

The problem is that when I run that migration against my PostgreSQL database, it’s assuming that default_venue_id is the foreign key for a relationship with the non-existent default_venues table and throws the following error:

PGError: ERROR:  relation "default_venues" does not exist
: ALTER TABLE "users" ADD FOREIGN KEY ("default_venue_id") REFERENCES "default_venues" ("id")

Should I be doing something to tell the database that I’m not trying to create a relationship or am I going about this the wrong way?

Edit: I’ve just realised that another developer who worked on the project added the schema_plus gem which automatically defines constraints for columns ending in _id

That explains why I’ve never run into this behaviour before!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T19:57:18+00:00Added an answer on May 31, 2026 at 7:57 pm

    It would be helpful to see the Models as well to diagnose this problem.

    However with that being said, I think that if you are using HABTM associations here it might be a good idea to take a look at a has many through relationship. example: VenueManagement which would have your user_id and venue_id. That way you could handle extra attributes on the association where it makes sense, like a default flag.

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Rails app, with 2 models : a User model and a
I have a model User and Listing in my rails app. User has many
I have a Rails 2.3.x app that implements the act_as_authentic in User model and
I have a simple model setup in my Ruby on Rails app. (User {name,
I have a rails app that is using Devise, with a User model, no
I'm building an app in Rails 3. I currently have a user model which
I have some rails app. For example I have next models: User , Post
I have a pretty basic 'User' model, control & views for a Rails app.
In my rails app I have a User model. In that model I have
I have a rails app which currently has 3 models: Post , User and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.