Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
added 297 characters in body
Source Link
maurice
  • 329
  • 3
  • 15

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.

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?

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.

Source Link
maurice
  • 329
  • 3
  • 15

When ids do not auto-increment as they should

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?