Quick question I think...
I've made a drupal site which has some custom content types. I've created a load of records with these, and then I've had to amend the custom content type to change one of the fields and give it a new default value.
The problem is that existing records do not update with this default value. Apparently i've got to go and re-edit everything to add the default value.
NEW records 开发者_StackOverflow中文版have the default value. No problem there.
Is this just a Drupal thing or am I missing a trick?
Thanks, Hugh
I'm pretty sure that this is a 'Drupal thing' (more precisely, a CCK thing ;)
I stumbled over this problem once and as far as I recall, found no logic in CCK to apply changes retroactively to existing nodes. So you'll need to ensure a load/save cycle for every affected node by some means. For small amounts, this might be done via one or the other bulk operation on 'admin/content/node/overview'. For bigger amounts of nodes, this might call for a little script calling node_load()
, node_save()
on all affected nodes.
Posting for anyone in the future: https://www.drupal.org/project/field_defaults
Allows you to update existing content when creating a field or editing defaults on an existing field
using sql , considering that nodes with the field value not set are
SELECT nid,vid
from node where type='procedure' and nid not in (select entity_id from field_data_field_pr_choix_du_document)
field_data_field_pr_choix_du_document being the table corresponding to my field and containing one entry par value set with entity id referinng the node
i did using SQL insert...select syntax
https://dev.mysql.com/doc/refman/5.5/en/insert-select.html
INSERT INTO `field_data_field_pr_choix_du_document` (`entity_type`, `bundle`, `deleted`, `entity_id`, `revision_id`, `language`, `delta`, `field_pr_choix_du_document_value`)
SELECT 'node','procedure',0,nid,vid,'und',0,'Importer un document'
from node where type='procedure' and nid not in (select entity_id from field_data_field_pr_choix_du_document)
精彩评论