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?