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 1062917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:42:16+00:00 2026-05-16T18:42:16+00:00

I’ve been working through some issues getting rails to behave nicely with sqllite, and

  • 0

I’ve been working through some issues getting rails to behave nicely with sqllite, and decided to move over to mysql.

I ran my rake db:create and rake db:schema, and assumed everything was ok, but then mysql show tables displayed a complete table was missing.

I created a migration with the create table details and ran rake db:migrate, and now the all the tables show up.

Unfortunately, it appears that the link between the tables didn’t work.

The app is a fairly simple recipe app.
The tables are

recipes
ingredients
steps

the ingredients table was the one which was not created in the db:create or db:schema.

I created the ingredients table with

class AddIngredientsTable < ActiveRecord::Migration
  def self.up
        create_table :ingredients do |t|
            t.string    :ingredient
            t.float     :amount
            t.string    :measure
            t.string    :description
        end
  end

In my recipes model i have has_many :ingredients, and my ingredients model has belongs_to :recipe

The error I’m getting is

Mysql::Error: Unknown column 'ingredients.recipe_id' in 'where clause': SELECT     `ingredients`.* FROM       `ingredients`  WHERE     (`ingredients`.recipe_id = 1)

and of course, the error is correct that a recipe_id field does not exist in either table. But I don’t have such a request in the controller either which reads simply

  def show
    @recipe = Recipe.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @recipe }
    end
  end

Any suggestions as to what to look for and why this problem might have occured, and how to fix it?

I’d prefer not to manually write out the sql as my understanding is that at this stage that isn’t the rails way, though I am familiar with sql so could do this.

  • 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-16T18:42:17+00:00Added an answer on May 16, 2026 at 6:42 pm

    Rails uses a lot of conventions. In this case you’re hitting the rule that has_many :ingredients on Recipe means that the ingredients table must have recipe_id. Obviously you probably want ingredients shared between many recipes, and so for that you’ll want has_and_belongs_to_many with a join table (which you will create another migration for).

    I suggest you start with this guide for a comprehensive overview of how this works in Rails.

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

Sidebar

Related Questions

No related questions found

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.