Closed (duplicate)
Project:
Drupal core
Version:
7.x-dev
Component:
field system
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
26 Jun 2010 at 03:17 UTC
Updated:
14 Jun 2020 at 17:39 UTC
Jump to comment: Most recent
Comments
Comment #1
joe.murray commentedOption 1: When deleting a content type, check whether fields it uses are not used by other content types. If not, add message about deleting field(s) unused elsewhere in system in content type deletion confirmation message. If user agrees to delete content type, also delete fields. Pro: keeps system clean, allows user to set new content type and add existing field before deleting old content type and fields.
Option 2: Allow 'orphaned' fields to be included in new content types. Pro: it can be time consuming to set up a field, and this approach allows that effort not be lost. Likely best if combined with Option 3.
Option 3: Allow 'orphaned' fields to be deleted.
I tend towards Option 1.
Comment #2
damien tournoud commentedThere are actually at least three issues here:
Comment #3
xmacinfoBefore changing the way content types detects and use fields, I guess we should upgrade the field list report (admin/reports/fields) to:
As a first step, that would at least let us identify quickly and possibly delete any orphaned field.
This would not solve all issues, though.
Comment #4
yched commentedThe UI is oriented towards masking the separate concepts of fields and instances. You get fields, and they can be used in several places.
This has a couple drawbacks, but keeps the concepts simple to grasp and avoids duplicating CRUD notions on two different levels. I'd rather keep it that way.
The UI on purpose doesn't handle 'fields without instances'. Internally, once the last instance of a field is deleted, the field itself is deleted (field_ui_field_delete_form_submit()).
Content type deletion doesn't run through field UI, though, but through code - field_attach_delete_bundle().
IIRC hardcoding field deletion in field_delete_instance() was considered and turned down as too harsh. Right now it's up to the code calling field_delete_instance() to decide - in this case, field_attach_delete_bundle(). I guess we could provide some helper code to ease that task; possibly even an optional param for field_delete_instance(), possibly even defaulting to 'yes, delete field if orphaned'.
I'm not sure this qualifies as critical, BTW.
Comment #5
xmacinfoThis is critical since you can't create a new field using the same name as an orphaned field.
Comment #6
klausiThis is annoying and a little WTF, but does not break overall functionality, neither of the field system nor of Drupal itself.
Comment #7
gstokes commentedSame problem here I have filed name I wish to reuse but cant as its still held in Database. I made a mistake in the choosing the type of filed and wish to remove it. This seems like pretty obvious piece of functionality.
Comment #8
yched commented@gstokes: let's not mix several things. This issue is about fields sticking around when a content type is disabled.
When a single field is deleted, it should currently be possible to create a new field with the same name straight on. If this doesn't work, please open a separate issue with a detailed description and steps to reproduce.
Comment #9
yched commentedMarked #944972: Filed name (exists but cannot be selected) as duplicate.
We need to fix this.
IIRC, my last thought on the subject was to add a $delete_field_too_if_last_instance param for field_delete_instance() - defaulting to TRUE.
Comment #10
nomonstersinme commentedI would mark this critical but I don't want to step on any toes. This is a HUGE issue IMO because most people will not understand what they did wrong and spend hours trying to figure this out. Yes, you can create a new field with a new name but thats really not a good solution.
Additionally upon deleting a content type and not its fields I get php eval errors:
Everyone has done so much great work on D7 It would really be a shame if this didn't get fixed before a full release... :/
Comment #11
yched commented#915906: Deleting node type with only instance of a field leaves the field in a strange zombie state has a patch, so marking this one as duplicate.
Comment #12
knalstaaf commentedNomonstersinme (#10): I think that issue may be php-module related: "Undefined variable: node in eval()" and "Trying to get property of non-object in eval()" error.
Comment #13
torinwalker commentedCan you guys suggest a temporary workaround? e.g. delete rows from some field_table, then drop the tables corresponding to the field_data_field_ and field_revision_field_, and any other relevant schema data? Just like the previous comments made, I've had some frustration setting up fields exactly the way I want - I'll create a field, then decide I want to change it's label or name only to find out it cannot be modified or changed. This is especially frustrating for the field values - if, as the warning suggests, once the data is created it cannot be changed, why present an editing field? I tried editing the data four or five times before I came to the realization that perhaps I wasn't doing anything wrong to edit the data, but that the data simply cannot be edited.... but that's another issue.
Right now, I want to re-use a field name without littering the database with previous instances of the field name (e.g. field_length_type, field_length_type2, field_length_type_3rd_times_a_charm, etc.), and the only way I can see doing this is to purge all relevant data from the database.
Thanks for any help.
Torin...
Comment #14
torinwalker commentedI figured it out. Thanks anyway.
Torin...
Comment #15
pixelsweatshop commentedTorin, can you share your workaround.
Can on just drop the orphaned table (and it's revision counterpart), or is the field registered somewhere else as well?
Comment #16
spyckedelic commentedI am still encountering this problem. No fix yet?
Comment #17
eidoscomI has the same problem and solved. Here is my workaround:
I did it accessing directly to the database. You have to delete 2 tables, delete one insert and truncate one table for each orphan field in drupal 7.
This worked for me, hope this may help you ;)
Comment #18
eidoscomFor a core fields like "body" or "comments" you must search for an instance records on the database inside the 'field_config_instance' table. There you can find records referencing the custom fields too.
Comment #19
anavrin commentedGuys , this should be solved a long time ago ... At least just to prevent to allow deleting the content types if there are fields:
1. used in other content types (i belive that's the real reason why the fields are not deleted automatycally when we delete content type)
2. used only in the content type that we are trying to delete - with comunicate -> you have to first delete all custom fields in this conent type manually...
That would change the situation from bug to need improvement...(and I believe it's not a big task for author of the module responsible for this functionality ...)
regards,
Marcin
Comment #20
xmacinfoIf you feel that is issue as not been fixed in #915906: Deleting node type with only instance of a field leaves the field in a strange zombie state, please change the status to “active”.
Comment #21
IreOke commentedTy so much, #17 works perfect for me, you saved my life!!!
Comment #22
svedova commentedWell I am using this code in a hook_cron:
This works for me.
Comment #23
jpsalter commentedThis cleaned out a lot of cruft for us
Comment #24
donquixote commentedComment #25
joelpittetD8 version in case people are looking for comment #22:
Comment #26
Michael G commentedModule Rooms and all related modules, can't be deactivated or uninstalled because of an orphaned field.
rooms_booking_unit_options
Any suggestions?...