Problem:
-------------
In a site recreated from a profile, creating a new node may result in an error like this:

user warning: Duplicate entry '1-1' for key 1 query: INSERT INTO node (nid, vid, title, type, uid, status, created, changed, comment, promote, sticky) VALUES (1, 1, 'Third Page', 'page', 1, 1, 1206934166, 1206934166, 0, 1, 0) in C:\bin\portable_xampp\htdocs\bare-drupal-5.7\includes\database.mysql.inc on line 172.

This error will happen in a newly-restored site, when creating the first node of a type which has at least one saved node entry in the profile.

This happens because the Profile Generator, when re-creating nodes saved in a profile inserts them into the DB in a manner which bypasses db_next_id, which is Drupal's mechanism of generating pseudo-autoincrement fields (Drupal does not use auto-increment fields and uses its db_next_id function to generate ids for fields such as nid where normally such a type would be used).

Reproducing the bug:
---------------------
Start with a brand new Drupal site, add and configure profile_generator module.
Create a Page. Save a profile and tell it to save Pages (checkbox at bottom) while saving it.
Delete the site and create a brand new Drupal site in the same location.
Add a folder named generated under profiles, copy the generated profile in there and copy the profile_generator module directory into site/all/contrib/modules.
Point your browser to the site location.
Select the generated profile.
Once the install is done you should see your Drupal site with your original Page node appearing on the main page.
Go to Create Content and create another page. You'll see the above message.

Any page created after that will be fine, because when db_next_id was invoked during the initial creation attempt (the one that failed) it adjusted it's data structures and now knows which is the next correct id for the field.

Comments

ench0’s picture

Correction to last sentence above: apparently db_next_id isn't that "smart" and will not figure it out on the first run. The error will happen as many times as there are nodes in the node table (i.e. as many nodes were saved with the profile). So if you had 2 pages and 1 story saved in the profile you'll have to attempt to create content 3 times (so that db_next_id runs 3 times and increments the index past 3) before this succeeds.

This can obviously be a huge problem for a site with lots of content.

One possible solution would be for Profile Generator to manually adjust the values in the sequences table? I dunno, though, maybe this is considered a big no-no by Drupal core maintainers...?

superjacent’s picture

I don't know why Drupal is programmed that way as tables do in fact use auto incremented values. If you're not directly modifying the sequences table how do you ultimately correct the situation.

Shiny’s picture

Status: Active » Closed (won't fix)

This is intentional - there are other tables referring to node 1, so we have to preserve it's name as node 1.