6

I have an sql dump file which I imported to my database. All of the records from this sql dump has id's starting from 900 to 2500.

So the problem is that If I will create new record from my rails app, it will get automatic id = 1, the next will get 2,3,4 etc. I guess when I i will create my 900s records, I will get an error, since id=900 already exists.

Note: I cant change my id's to start from 1 in my sql dump file, since another table references it by id.

Is there any solution?

I use PostgreSQL

0

1 Answer 1

6

Rails gets the id that it uses from the database, in the case of postgres there are corresponding sequences for each table's id field, so in order to get Rails to skip over that block of ids you just need to update the corresponding sequence:

ALTER SEQUENCE plural_table_name_id_seq RESTART WITH 2501;

You could put that into a Rails migration if you liked, or just run it on your databases.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.