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

  • Home
  • SEARCH
  • 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 618523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:33:19+00:00 2026-05-13T18:33:19+00:00

I have a table that has following columns id store_id store_name id and store_id

  • 0

I have a table that has following columns

id   store_id   store_name  

id and store_id are always going to be same. Since I am new to rails…I had created it by mistake. But I can’t afford to go back and change stuff now since I am using store_id at a lot of places.

Issue 1: I am making admin screen for this table. When I try to insert a record, eventhough, id gets inserted (rails automatically gets the next one) NULL is being inserted in store_id.

Is there any ways I can have same number in store_id as in id while inserting record using the create method. Is there something that can be put in the model so that it is always execute before creating a record. and there I can have access to the next Id that should be inserted?

Issue 2: Since I am making admin screens for this table now..before I was just inserting data into this table by hand. I have inserted 5 records by hand so id and store_id 1..5 already exist. Now when I try to insert a record from admin screen it says duplicate key violates constraint. could it be trying to insert id of 1 since this is the first time I am inserting record to this table using rails?

  • 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-13T18:33:19+00:00Added an answer on May 13, 2026 at 6:33 pm

    Issue 1: Until you can remove the store_id column, override the getter in the model for compatibility.

    def store_id
      id
    end
    

    As for Issue 2: make sure your create code is not manually setting the id. The next record should be inserted with id 6, as long as your object has no id defined. Try it from script/console.

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

Sidebar

Related Questions

I have a MSSQL table stores that has the following columns in a table:
I have an table in my MySql database that has the following columns: -
i have a table that has following column Type -------- type 1 type 2
I have a table that has multiple rows with the following fields: PersonName SongName
I have a SQL database that has the following table: Table: PhoneRecords -------------- ID(identity
I have a table that has two datetime columns (one for start time and
I have a table that has account numbers in (account_num) and user profiles (profile_id).
I have a table that has duplicate email address, I need to insert just
I have a table that has no primary key, and one cannot be created
I have one table that has two fields - ID1 and ID2 ID1 can

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.