| Drupal

delete-items

Here are two of the most common questions we get from Drupal newcomers:

  • "What happens if I delete a content type?" 
  • "What happens if I delete a field?"

Because the answers are not easy to find, these kinds of questions can be confusing.

Here's a clear explanation of what happens when you delete a content type or field.

Deleting a Content Type

media_1366034019067.png

There are three questions to consider when deleting a content type:

  1. What happens to the content?
  2. What happens to the fields associated with the content type just deleted?
  3. What happens to the modules that interact with deleted content type?

1. What happens to the content?

media_1366034688178.png

The short answer to this question is, the nodes remain in the database. You can see the nodes listed in the Find Content admin page.

However, just because you can see them listed, does not mean you can open them. In fact, you can't; you get an error if you try.

2. What happens to the fields in the deleted content type?

media_1366034448486.png

The test content type that was just deleted had a test field (a field unique to the test content type) and the image field that comes with the Article content type. As you can see from the screen shot above, the image field is still there but the test field is not.

3. What happens to the modules that interact with the deleted content type?

There are contributed modules that add features to content types such as AddToAny and Webform to name two. In order to add the features provided by the module to the content type, quite often you check a box on the module's configuration page. The module then stores that decision as a configuration setting in the database.

What happens if you delete a content type without telling the module that is no longer needs to do something to that content type? In order to answer this question, I'd have to test quite a few modules to see if the developers of those modules took steps in their code to accommodate a content type suddenly going away. I offer you this however, if you have a content type you want to delete and you have modules on your site that add features to content types, consider disconnecting the content type from these other modules before you delete it.

Deleting a Field

In order to delete a field, you must go the content type where the field resides and delete it, unless of course you are deleting a content type. We saw earlier what happens to fields when we delete a content type. The fields shared across multiple content types remained but the fields unique to the deleted content type were also deleted. This same logic applies when you simply want to delete a field.

If the field you delete is unique to a content type, then the field is gone from the database (that includes it's data). If you delete a shared field from, the field is removed from that content type along with the data unique to the content type. The field remains intact for other content types to use.

If you find that you need to keep the data associated with the field but you need a different type of field for the data, you need to plan ahead.

  1. Create the new field.
  2. Devise a way to migrate the data from the old field to the new field.
  3. Delete the old field.

Summary

Before you delete anything in Drupal, ask yourself how the "thing" you are about to delete is related to other things on the site. Is the content type related to existing nodes? Does the content have features managed by other modules? Has the field been used? If yes, will you need to save the data stored with the field?

Think things through before you delete.