8

I tried creating a field, but my server crapped out halfway with an Internal Server Error due to some spambot attack...

Now, when I try to add the field again, I am getting:

The machine-readable name is already in use. It must be unique.

I guess some tables were populated in the db. How can I remove these easily?

1

2 Answers 2

27

You can also use drush to run field_delete_field(). Just run:

drush eval 'field_delete_field("yourfield")'
3
  • 1
    Good call, much cleaner than hunting through the db. Run cron afterwards too or field_purge_batch(). Commented Aug 4, 2014 at 10:04
  • 2
    This is excellent! FYI that function doesn't completely delete the data. It adds a db table for each field whose name begins "field_deleted_data_". That's probably a good thing. But folks might want to finish the job by dropping those tables.
    – Shai
    Commented Jul 16, 2015 at 15:18
  • 1
    Data for deleted fields is purged during cron runs. Please do not drop those tables, as it could WSOD your drupal site. Commented Sep 16, 2015 at 15:37
4

Wow creating a field takes like 2 seconds ... but if it crapped out, i guess it crapped out.

Since you dont know "where" it crapped out basically you'll have to look for the tables to be sure you clean out whatever IS there ...

  • Drop the tables field_data_FIELD_THE_NAME_YOU_GAVE_IT and field_revision_FIELD_THE_NAME_YOU_GAVE_IT.

  • Also in field_config and field_config_instance look for name keys (and the bundle keys) for the field + bundles you tied the named field to. Delete those entries in those 2 tables as well.

  • Clear your site cache.

3
  • 2
    Please do not do this. See answer below: field_delete_field() which will invoke any relevant hooks and clean up cache as well. In general, if you are writing SQL or operating directly in the database, you're doing something wrong. Commented Sep 16, 2015 at 15:35
  • 1
    If the addition of fields failed in the UI. Why would you assume the API will still work to delete malformed data/tables? I agree with your overall reply, I disagree with it for 100% of all cases.
    – tenken
    Commented Sep 16, 2015 at 15:52
  • You're right - i did not thoroughly read the original question. My bad! Preferred method is to use field_delete_field(), but if it fails then going directly to the database is probably the best / only alternative. Commented Sep 16, 2015 at 20:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.