So I'm installing a new Drupal site (5.7). I have taxonomy terms from an old drupal site (4.7) I wanted to bring across. DB is on the same server. For many reasons, I didn't want to upgrade, especially because the old site is flexinode and the new one is CCK. I did find a useful article for this type of conversation but there were a lot content types that needed to be revamped.
I compared the term_data, term_hierarchy table's fields and they were the same on old and new DB. So I did an INSERT into newDB (one, two, ..) SELECT FROM oldDB.... Everything went through. I checked and they were identical.
Checked under categories and realized nothing was there. Added a vocab and everything that I had ported across now showed up. "Great!", I thought to myself.
The twist I can't figure out: I added a new vocab. I tried to add new terms. Guess what??:
user warning: Duplicate entry '1' for key 1 query: INSERT INTO beta_term_data (tid, name, description, vid, weight) VALUES (1, 'Test', 'test123', 2, 0) in /public_html/beta/includes/database.mysql.inc on line 172.
I'm thinking to myself that Drupal (Taxonomy) has a variable elsewhere that gets incremented each time a new term is added. I can not find this to change it. I've tried reading the Taxonomy.module but it's not coming to me.
Hoping someone can shed some light on this or advise. Thanks!
Comments
Yep. the sequences
Yep.
the sequences table.
Active for many tables, and you need to get friendly with it if you are doing open-heart operations on databases
.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/
.dan. is the New Zealand Drupal Developer working on Government Web Standards
since you've been sooo helpful...
i wanted to make one last request...just to save me time, that's all. purely up to you. i'm asking because someone else answering yay or nay is still usually faster then digging entry after entry to find an answer.
ultimately, i have to convert stuff from flexinode to my new node type. i'd need to pull data across and mass dump into new DB. do you have any tips or know of any really indepth articles *off the top* of your head that gives me an idea of how a node is inserted into the DB...as in, how many other tables besides NODE gets changed, etc.
i'm asking for minimal time: maybe two minutes to references you might know. if you'd like to say a little more, i'd really appreciate it as well. i'm going to continue looking but hoping that maybe you'll come up with a brilliant answer faster than i can find my answer on google/drupal.
thank you once again.
Use the API, stop messing with the DB directly
Definitely stop messing directly with SQL if you are talking about flexinode or anything beyond title & body.
Write your own little import script (from a php-content page if need be) that uses the API.
Build a node object from scratch, containing the basic fields, then populate it with your own values (which you fetch from your own lookup) , then node_save() it.
get a print_r() of your target content type, with some sample values in it, to see the structure you need to replicate.
That'll take care of all the extra BS like revisions and increments also.
.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/
.dan. is the New Zealand Drupal Developer working on Government Web Standards
Thanks for the response!
Thanks for the response! It's going to take me a few days to dissect and understand what you said in Drupal/dev terms. I'm not too familiar with the API's yet. Still learning it. Right now, I'm still trying to master theming. Not sure how I'm going to code it yet but I think I'll *eventually* understand what you said. Presumably, I will be studying the API's that deal with nodes...?
I'm sorry if this is taking up more than you'd like and I'd understand if you didn't respond after this one. But here's how I was anticipating on doing it (only because it was the most straight forward way for me with the time limitation I have). You can almost consider it reverse engineering Drupal.
1. Study the tables in the oldDB. Insert a new node using through the old website. Note changes made to the DB. (probably impossible to get it all).
2. Create the new content type with CCK fields that I wanted in the New website. Insert a node also through the website. Note changes to the DB.
3. INSERT into newDB SELECT from oldDB, the fields/tables that I want. Make necessary changes to any other DB's that help "sequence". Worse comes to worse, scratch and try different method.
4. Test.
I'll study the API's a bit more though. Again, thank you for reading this far! =D
Thank you
Hey Dan,
Just wanted to say thanks again. After a lot of trial and error, I managed to get it to work....sorta of in the same direction as what you had suggested in your initial comment..but not quite the same. I did get critical data across into the newDB. But I wanted to share my particular method with you if you're interested in commenting any further.
1) script written on a Page Type (accessible from node/4312). the script basically was a for loop that did a node_load($nid) from 1 to 4311 and wrote to an external file (export.txt). see output below. this exported the very specific pieces of data that i wanted in the form of a a new node. the script was fined tuned by looking at a print_r($node) (of the target node type you mentioned). (Now i understand what you meant by build a node from scratch.)
2) Wrote an external PHP script (bootstrapped Drupal manually). Placed this script in the root directory of the newDB. Due to memory issues on the server, I had to do several exports, eg 1-500, 501-1000, etc... and then do multiple imports too. but it worked. the import consisted of a series of copy from export, paste into import.php, save import.php, run import.php from browser. rinse. repeat. though still not as bad any manually entering one node at a time via the GUI of Drupal, it was still a tedious process.
I however still couldn't figure out how to write a script that directly pulled from oldDB and dumped into newDB using Drupal or an external script. I thought about how I would do it via the bootstrap process but I could only bootstrap one instance of Drupal at a time. I guess i don't understand it enough. I'm sure you would've written a much fancier script that did an export from oldDB and immediately dumped it into a newDB.
But this is a one time thing. Hopefully, I'll never have to do this again..although it was a good learning experience because i'm a lot more comfortable with the backend now. I'm sure once I get more comfortable with Drupal then I'll probably be able to write smarter code.
Cheers!...Hope this helped someone else.
Glad you figured out the
Glad you figured out the bootstrap process. I've not used it myself, but that's certainly a go.
While your process works, there's clearly a bit of room for improvement (not that it matters once you are done)
I don't know what the best approach is for accessing two DBs simultaneously, so the first couple of times I did some raw imports ... I placed the data into a temp table! It looks like your node definition is pretty 'flat' so it could be exported into a half-dozen columns.
Shift that table to your target and then loop the create process you've listed above.
FYI, the cck field 'value' value is the 'cooked' representation of how it would appear on screen (eg, after input format filters are applied) ... it's the 'data' value that counts for saving. I can see you were just being safe and copying everything, so no harm done.
.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/
.dan. is the New Zealand Drupal Developer working on Government Web Standards
Thanks again!
Hey thanks for the tip on CCK. My import script will be much simpler next time.
And thanks for reminding me about temp tables. I didn't even think about. I totally could have used them especially since the old Drupal site and the new Drupal site ran on the same database. The new Drupal site uses beta_ prefix for its tables. I guess I should have mentioned this initially as well.
But I'm not to fond of the way Drupal sets up arrays and nested arrays. I get confused. Haha. I think once I play with it a little more, perhaps even writing a few modules (I've got soo many ideas in my head, useless or not)...then i'd be more comfortable with traversing Drupal's arrays...etc...
But yeah. Thanks again dude. Most appreciated!