We can create the node.

However when a node is saved, and Create Revision is checked, the node does not get saved.

In watchdog, there is an error which says that BODY field does not have a default value. In the INSERT to node_revision, there is no BODY field being saved, as such the whole record is not created.

This returns a VID to be 0 and the subsequent fields are not saved as well.

Comments

yched’s picture

Project: Content Construction Kit (CCK) » Drupal core
Version: 6.x-2.2 » 6.10
Component: content.module » node system

Not related to CCK: CCK doesn't handle the node body 'field' or revision creation.

jbeall’s picture

I'm having this same problem. It may not be CCK's "fault" but it is (at least in my case) *related* to CCK.

I created a new content type, with a whole bunch of custom fields via CCK, and I got rid of the body field. When creating a content type, it says "To omit the body field for this content type, remove any text and leave this field blank." "Great!" I thought, that's just what I want. We don't have any particular field for this content type that is the "body," -- all of the fields, arranged together, form a "body" for the node, but there's no separate body field.

But, now that I'm trying to do revisioning in this scenario, I can't save any additional revisions because, as the original poster noted, it's trying to insert a row into the node_revisions table without a value for body, and that field doesn't have a default value. Not only that, since it's a LONGTEXT column, it *can't* have a default value. Trying to set a default value results in a MySQL error, "#1101 - BLOB/TEXT column 'body' can't have a default value."

So this needs to be fixed in code. When a a new row is inserted into the node_revisions row, if there's no body value, it still needs to insert an empty string in order to make the SQL work.

So I think this is a revisioning module issue...?

-Josh

jbeall’s picture

Ok, after some digging I think I found the solution. It's a one-liner, I hope we can get this into the next release of Drupal.

modules/node/node.install needs this (starting on line 213):

'body' => array(
'description' => 'The body of this version.',
'type' => 'text',
'not null' => TRUE,
'size' => 'big',
'default' => ''),

It was this:

'body' => array(
'description' => 'The body of this version.',
'type' => 'text',
'not null' => TRUE,
'size' => 'big'),

You can see that I added a "default" key with the value of an empty string. This seems to be all that was necessary.

I've manually patched my installation of Drupal, but I don't want to have to keep doing that every time a new release of Drupal comes out...

eric_a’s picture

Status: Closed (duplicate) » Active

The node_save() function sets undefined teaser, body and log properties to the empty string in order to allow for an INSERT into the node_revision(s) table with it's corresponding non-nullable collumns.

*It does this when saving new nodes, but not when saving new revisions.*

Scenarios are possible where a new revision has to be saved for a node object with an undefined body, teaser and or log.

The logic in node_save() needs to be fixed if the above analysis is correct.

The solution in #3 tricks drupal_write_record() into setting default values even if default values cannot exist in the actual database schema. @jbeall: it is as ugly as it is quick! ;-) Brilliant for those who need an immediate fix.

damien tournoud’s picture

Version: 6.10 » 7.x-dev
Priority: Normal » Critical
Status: Active » Closed (duplicate)

This looks like a duplicate of #261258: Fix node_save() insertion logic.

JvE’s picture

Issue summary: View changes
Status: Active » Closed (duplicate)