Is there process by which field settings can be modified after there is data in the database. I've created a date field that collects hours and minutes, but i want to change it so that it just collects years, months and days. Is this possible.
Currently its not modifiable and displays this message "There is data for this field in the database. The field settings can no longer be changed."
It doesn't seem unreasonable that you should be able to reduce the amount of information collected, then the time after the T could be ignored in the date time database entry. In fact perhaps its also possible the other way too, if there was no time added in the first place a standard time could be used.
Is this possible, or is there a script i could run that would update all the entries.
Comments
Comment #1
KarenS CreditAttribution: KarenS commentedYou will see the same restriction on all fields, not just date fields. You can't alter the field settings after there is data.
If you want to make changes like this using scripts, you're on your own. If I provided scripts to do that I would also become responsible to fix all the things they might break. If you study the Field API and the Date API, you might be able to figure out how to alter the settings in the database, then you would have to run batch scripts to update the data to match the new settings. It's quite tricky to alter the field structure after its been created because the data no longer matches the settings and you can end up with lots of unexpected consequences while you try to get them aligned.
A better path would be to create a new field with the settings you want, then use a script, or something like the Migrate or Feeds modules, to copy the data from the old field to the new one.
Comment #3
earwax CreditAttribution: earwax commentedWhat is funny is that the message makes you believe you cannot make changes. This is not true. You can still go ahead and edit the field setting and make the changes to capture your new data types. Think of it more as a warning instead of a "cannot do". Just be aware that now you will have inconsistent data in your table(s). You still need to fix those yourself.
Comment #4
earwax CreditAttribution: earwax commentedWell I take this back. It turns out it is not always the case. I think we are S.O.L in this case.
Comment #5
geerlingguy CreditAttribution: geerlingguy commentedJust for those daring enough to try to actually change some things with data existing in the database (if, like me, you don't want to have to create a new field/field id, then migrate your data, then update your custom code to use the new field id for everything, and delete the old field...), here are a few tips:
Comment #6
Steve Polito Design CreditAttribution: Steve Polito Design commentedOne Method Could Be To Export and Re-Import the Data
I wrote a tutorial explaining how to do this.
Comment #7
devasgharDo this on development site, not recommended on production sites.
Case : If the backend structure of you new field is the same as that of the old one
Step 1 :
Backup sql table of the field see machine name to target the exact table
Step 2 :
Create a new field and restore the backup to the table of the new field see machine name to target the exact table
#6 is probably what you need