I must be really dense today. I can't see any way (in the Drupal interface) to delete a CCK field. I see how you remove it from a content type, but I need to delete some completely, as my list is getting cluttered with "test" fields that didn't quite work out... TIA

Comments

shunting’s picture

I have the exact same problem.

adam_b’s picture

ica’s picture

content_type_cleanup cleans / deletes all your chosen content type nodes NOT the content fields
because there is no a paragraph of description or documentation what it exactly does it may lead you delete all your nodes on chosen
you might loose your precious content if you misunderstood this -I did
the name of the module misleads its function
a function which really does allow you handle and delete the custom fields still needed though

doc2@drupalfr.org’s picture

I have the same needs...

pembeci’s picture

I searched the CCK issues but couldn't find anything there. You can delete it from the database but you must be very careful to do so.
Before going into the database I think you should do these:

  • delete any cck nodes that use that field
  • remove the field from any content type which included it
  • make sure you are not using a view that references that field. if so remove the field from that view also.
  • if you are using any contributed module that may use that field, you should go and remove the field from that module's components.
  • now we can move to the database. check each content_type_* table and remove the field row if it is still there.
  • check node_field table and delete the field row there.
  • check node_field_instance table and delete the field rows there.
  • check node_group_fields table and delete the field row from there. this is added by the field group module I think. so you may not have it.
  • finally find the table content_field_* where * is your field's name and then remove that table altogether.

As you can see this is very error prune and you may miss something. Actually I am not sure if I miss anything above. So the more correct action to take is open a CCK issue at the project page.

heathergaye’s picture

Thanks heaps for this checklist, just what I was after.

pembeci’s picture

After reading the later comments, may be if you do the first part (the actions before we move to the database), may be Drupal will allow you to remove it from the admin pages.

nevets’s picture

Under "Administer" > "Content management" > "Content types" cliick edit for the content type you want to remove the field from. Then click the "Manage fields" tab. If the field can be removed it there will be a 'remove' link under 'Operations'.

doc2@drupalfr.org’s picture

Sometimes a field can't be removed through the User Interface. This is very anoying.

So now I go to the url of the confirmation page for the removal of a valid field (ex.: admin/content/types/nodetypeofyourfield/fields/field_yourfieldsmachinename/remove), and I change the field's machine name with the one I want to delete as it appears in admin/content/types/fields. Of course, you'd better not use it anymore.
Advantage: no hack in the DB, the work is done by drupal.
Good luck.

EDIT.: As far as I remember, nodetypeofyourfield in the first url seems indifferent. Indeed, you could have no nodetype for your field to be assigned, you can still use any nodetype in your url, drupal will do the work. If not, please report!

zevans23’s picture

Thanks, worked perfectly for me. Is this fixed in D7?

jamesrutherford’s picture

It appears if you remove a field from all content types, the system removes it. That is probably why the field list doesn't have an actual delete button. Not intuitive, but it works.

zbricoleur’s picture

...6, or 5.x?

dgoldston’s picture

Yes it will delete the field completely, but to remove the reference from every content type is tedious. A simple removal is needed. This would allow the ability to save these fields for later use as well.

jarula’s picture

$type = 'mytype';
$content = content_types($type);
if (count($content['fields']) > 0){
include_once('./'. drupal_get_path('module', 'content') .'/content_crud.inc');
foreach($content['fields'] as $key => $field){
content_field_instance_delete(array('type_name'=>$class->pcid,'field_name'=>$key));
}
}

mikeytown2’s picture

Works with the latest CCK

function my_update_6000() {
  $ret = array();

  // Load up cck crud interface
  module_load_include('inc', 'content', 'includes/content.crud');

  // Remove old fields
  content_field_instance_delete('field_a', 'page', FALSE);
  content_field_instance_delete('field_b', 'page', FALSE);
  content_field_instance_delete('field_c', 'page', FALSE);

  // Remove old groups
  fieldgroup_delete('page', 'group_x');

  // Flush caches
  content_clear_type_cache(TRUE);
  menu_rebuild();

  $ret[] = array('success' => TRUE, 'query' => 'removed old cck fields from page content type');

  return $ret;
Lucidity’s picture

Just change the number of values (I don't know whether this is the right english translation) to number of fields you want. Now you've got the right number of fields, if you want to add another field just set the number of values back to unlimited.

akanik’s picture

As of Drupal 7, running all current modules and core (as of April 15, 2011) you can delete a field using the drupal interface! Steps:

1) go to admin/structure/content types
2) select any content type that includes the field you are trying to delete
3) select the 'manage fields' tab at the top of the page
4) locate the field you want to delete and select that field (link text in the column 'field')
5) you will most likely come to a page called 'field settings' that has an error message at the top, something about not being able to change the field because data has already been entered into it
6) click the 'delete' tab at the top of that page

And that is that. Others have said this and take notice, deleting any field will lose you all of your information that was held in that field. Make sure you actually want to do this before you do it!

AMENDMENT: I just realized that although this removes the field from all of your content types, it does not remove it from the database.... which means that you just can't use that field name anymore....

RobW’s picture

If you're using Drush:

> field-delete yourfieldname

This completely deletes the field -- you can re-use the field name for another field if you like.

Here's your docs.

apotek’s picture

This thread is d5 (but also applies to d6). The drush command field-delete requires D7. And of course in D7, the problem identified by this thread is no longer a problem :)

$ drush field-delete content_field_video
Command field-delete requires Drupal core version 7+ to run.  

mah ham

oknate’s picture

Tread lightly when doing this, and backup your database beforehand. Make sure none of the inactive fields are used on other content types.

     $content_type = 'franchise';
    $inactive_fields = content_inactive_fields($content_type);

    foreach($inactive_fields as $field_name => $field) {
      
    $used_on_other_content_type = (int) db_result(db_query("select 1 from content_node_field_instance WHERE field_name like '%s' and type_name != '%s' LIMIT 1",$field_name, $content_type));
    
      if(!$used_on_other_content_type) {
        if($field['multiple'] == 0) {
            foreach($field['columns'] as $column_key => $column) {
              db_query("ALTER TABLE content_type_%s DROP column %s",$content_type, $field_name.'_'.$column_key);
            }
          } 
        else {
          // if multiple, uses a separate table
          db_query("DROP TABLE %s",'content_'.$field_name);
          db_query("DROP TABLE %s",'node_data_'.$field_name);
        }
          
        db_query("DELETE FROM content_node_field WHERE field_name = '%s'",$field_name);
        db_query("DELETE FROM content_node_field_instance WHERE field_name = '%s' AND type_name = '%s'",$field_name, $content_type);
     }
    } 

In drupal 6 there is a function content_field_instance_delete that deletes fields. If there are no remaining instances it will delete the column or table.

summit’s picture

Hi,
I have a non-node field I want to purge. I want to keep the field, but purge the values without having to go into the database.
It is a commerce-order field which is wrongly shown in test.
Is there no module to remove the values of a field within Drupal when the field is not attached to a node, but another entity?

Thanks a lot in advance for your reply!
greetings,
Martijn