views:

20

answers:

3

Can I change node ids (nid) in mysql tables in order to update the IDs of the nodes in Drupal ?

In other terms, if I change the nid (paying attention to keep they unique for each node) in the 'node' table, directly from phpmyadmin, am I going to introduce bugs ?

thanks

A: 

I think it may work.

You need to keep in mind that the nid is not only referenced by other tables but can also be defined in some serialized data. If you serach through the whole database and make sure to change EVERY possible occurence of the nid, than it should be doable.

DrColossos
uhm, how can I find EVERY possible occurence of the nid ? I guess this is tricky and very risky.
Patrick
It is, absolutely, but with phpmyadmins search functionallity, you should be able to find all occurences within serialized data. But I doubt that the effort is really worth the effort.
DrColossos
Yeah but I have thousands of nodes.. I've been convinced by other guys to not doing that. I was wondering if I can pass the nid value when the node is created. In this way I don't have to change it later.
Patrick
+1  A: 

The node id is used in a lot of places, so you have to be very careful doing something like that. It may very well lead to things breaking, like missing the content of the node which is stored elsewhere.

If the nodes are freshly imported it makes things less tricky, but it's hard to be sure you get everything right. The problem is that you might only find the problem when it's too late.

I believe that migrate creates some kind of join table when you import nodes, can that be used to match the node ids to the old ids?

googletorp
mhm... ok. The reason why I want to change it is that I need sync the id created by drupal with the ids imported from an external table (from which I import the nodes).
Patrick
did you update your answer ? If you update it without posting at least a comment, I don't notice the change!How could the join table help exactly ? I need to assign the "answers" to the "questions". That's why I need to keep consistent the nids.
Patrick
A: 

Considering that a node ID could be saved in a database table created by a third-party module, I think it's quite impossible to be sure to not create problems. If you run the SQL queries by hand, you need to be sure you checked every single tables, including the cache tables, which could contain a reference to a node into a serialized PHP object, or array.

kiamlaluno

related questions