1

I am trying to import existing data from 2 tables into a rails app, and having a strange issue related to ids. All the migrations creating the tables seem to adhere to conventions (no specific mention of id field, just leaving that to rails to figure out). Basically I am sending in an ajax object for each object in table A, which belongs to an object in table B. I have a field in object A called object_b_name, and a mutator method that does a find_or_create_by_name based on object_b_name, returning object B's id to use in object A.

On my local server, the objects in table B have consecutive ids. But on the remote server, running the same code, those objects all have id 0. What would cause this?

Edit/Update: Upon inspecting the schema in the remote server, it turned out that there was no auto-increment or index on the id field (as @Sammitch mentioned), so I'm guessing someone else on the project created that table manually for some reason. Adding those constraints resolved the issue.

1
  • 2
    I would venture to guess that your id column on the remote server has neither a unique key/index, nor AUTO_INCREMENT defined on it. Commented Sep 13, 2013 at 18:00

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.