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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:40:25+00:00 2026-06-13T20:40:25+00:00

I used a migration in ruby to create these tables together with a model.

  • 0

I used a migration in ruby to create these tables together with a model.

I have a Table Information and a Table Detail, each entry in the information table can have one association in the detail table.

So i created them with:

create_table :details do |t|
      t.integer :id
      t.string :Bezeichnung
      t.binary :Koordinaten
    end

 create_table :informations do |t|
      t.integer :id
      t.integer :DetailID
      t.integer :Longitude
      t.integer :Latitude
    end

In my Information Table i got a DetailID which should Reference to the id of the Detail table.

Now i did:

ALTER TABLE informations
      ADD CONSTRAINT fk_informations_details
      FOREIGN KEY (DetailID)
      REFERENCES details(id)

Is this correct? Have i set the FOREIGN KEY correct? Or do i have to put the foreign key in the other table!?

Because i want to use in my Information Model following:

has_one :detail, :foreign_key => 'DetailID'

And in the Detail Model following:

belongs_to :main
  • 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-06-13T20:40:27+00:00Added an answer on June 13, 2026 at 8:40 pm

    Some notes:

    1. Perform all kinds of alterations on the database using migrations, never do them by hand.
    2. Use Ruby on Rails naming convention whenever possible. This means using detail_id instead of DetailID
    3. Your associations are wrong.

    If Information has_one :detail, Ruby on Rails will look for an entity with a matching information_id in the details table.

    In your model, it is the other way around – the Information contains a detail_id. In other words Ruby on Rails would specify this as Information belongs_to :detail and Detail has_one :information.

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

Sidebar

Related Questions

I have an mdb which used to contain a bunch of linked tables. These
I'm trying to create a migration for a simple table that is just used
I am developing an EF - MVC 3 application. I have used model first
Let's say I used the following command to create a User model: script/generate model
In Yii framework I used migration just like ./yiic migrate create tbl_demo it made
I have used the migration feature in WebMatrix to migrate my .sdf database to
Does anybody using latest enterprise library 4.1 in mono? I used mono migration analyzer
I am migrating application from JSF1.2/MyFaces+Facelets TO JSF2.1/MyFaces. I have following template which used
I used the phonegap website to create an IPA file. Now I want to
Having used storyboards for a while now I have found them extremely useful however,

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.