Say I have a CSV of nodes, that have completely different nid's from the table I want to import to (which already has data).

So table 1 that I want to append more data into has:
nid vid title
4 5 abc
5 7 bbc
6 7 cbc

And the table2 I want to export and import to table 1, has:
nid vid title
2 3 wfw
3 5 32f
4 6 3f2

How would I insert table2, into table1, without messing up the IDs? Should I just invent a random large number for nid ?

23532 3 wfw
23533 5 32f ....

And then hope that drupal was smart enough to not throw errors when the autoincrement gets here? I also notice that Drupal doesn't use autoincrement attribute in mysql, so I'm confused as to how they work with IDs.

Any information will be appreciated. (I also checked, entering null causes errors too).

Comments

da_solver’s picture

Hi,
If your installation is using a relational database engine like MySql or Postgres it's likely you can import the data directly with the database engine. I know both MySql and Postgres have functions to import data from csv files (I've imported data from csv files with both MySql and Postgres).

If you are using either MySql or Postgres database engines, I would check the engine's documentation for details.

As far as the nid field, don't add the existing values from your csv file. Let the database engine create new values.

Hope that helps.

executex’s picture

>Let the database engine create new values.

Yeah, MySQL doesn't create it. How do you create it? That is the question here. How does drupal create it?

Drupal isn't using auto_increment attribute, so I cannot just use the database engine to auto-add. Someone needs to explain how Drupal is adding IDs into the database first and how to add new nodes through an SQL query.

da_solver’s picture

Hi,
It's the database engine not Drupal that executes a table attribute like "auto_increment". Run "explain" against the node table. The "nid" field is set to "auto_increment".

Where in the source code is Drupal generating "nid" values? Please post file and function :)

How about positing the output from "explain" in the node table?

executex’s picture

Ok I was looking at wrong table, the nid/vid values are autoincrement in their respective tables.

So I first insert to node, then get nid there, and then insert to node_revision get vid there, then to content_type_x then to node_comment_statistics. And apparently my nodes don't have term/category relation so I don't have to insert to term_node.

nevets’s picture

There are modules that allow you to import nodes from csv, Node Import and Feeds are two of them.

executex’s picture

Node Import has an error in it that cannot be fixed. So I cannot use that for my project. I have too many CCK fields that are messing with it.

nevets’s picture

What about feeds then?

da_solver’s picture

Hi,
If the node table nid field does have "auto_increment" removed, he's got a corrupted schema. Installing third party modules not going to fix that.

executex’s picture

I don't really want to learn a new module only to find out that it can't export and import my data due to certain CCK fields. I'd rather just manually do it on the database.

da_solver’s picture

Hi,
"Explain" isn't a Drupal contributed module, it's a MySql command.

  • Log in to the mysql command line: $> mysql -u username -p database name
  • mysql> explain node;
executex’s picture

I know that. I don't need to explain it, since I can see it in phpmyadmin. I was replying to other guy about feed module.

da_solver’s picture

Hi,
Good luck :) Looks like you are going to need it :)

executex’s picture

Ok. You were very helpful thanks.

WorldFallz’s picture

just an fyi-- another option is the http://drupal.org/project/migrate module.

biigniick’s picture

hi,
this seems to be a similar problem that i'm running into. i have 1800+ nodes to add that all have several fields with them. i thought the best way to do this would be manually add them to the MySQL database. . . but now they don't show up. i added all the dbname.field_data_fieldnamehere and dbname.field_revision_fieldnamehere and the dbname.node and also dbname.node_revision and dbname.node_comment_statistics

am i missing something? or is this not supposed to work? i'm still a bit of a drupal noob, any help would be appreciated.

thanks,
- nick