1

I am working with a company setting up a drupal website. I am responsible for entering our product information into the drupal tables. I am having difficulty getting a straight answer/an answer that makes sense as to what the values for nid and vid should be in the drupal_node and drupal_node_revision tables should be. I am being told by our vendor that the values for nid and vid need to be the same (ie 27 and 27) but that doesn't make sense to me. Shouldn't the vid just start at 0 or 1 and increment up from there. Isn't it simply what the node table uses to read the current version from the revision table.

I know very little about drupal so I may be wrong but their answers aren't making sense to me. And as the nid is automatically incremented in the table, I have no way of knowing what the nid value is until after the insert. So I would have to read the value and run an update statement, which seems really sloppy.

1
  • Are you trying to "write" nodes directly to the database? The node id (nid) and revision id (vid) should be handled by the Entity API when you create nodes using entity_create() or the UI.
    – njp
    Aug 12, 2013 at 16:09

1 Answer 1

2

If you begin to add nodes and never edit them, like you would do when migrating data to a new Drupal installation, then the nid and vid would increment at the same pace, and would happen to be the same. After first edit though, assuming you have revisioning on, the new vid would be what ever is the next available number for all revisions.

2
  • So, do they have to be the same at the beginning? For my example each node corresponds to a specific product. Should the revision id's start at 1 or the corresponding node id?
    – Nick
    Aug 12, 2013 at 18:39
  • I was just describing what happens when you create nodes with node_save or in the UI, and then edit them. You really don't need to worry about vid when using node_save or UI. For entering your data one good way is to create nodes with node_save function. There are also modules for that, for example Migrate. Writing sql for creating nodes directly to the database is the hardest way, I think. Aug 12, 2013 at 19:23

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.