Programatically Attach a Field to a CCK Type in Drupal 6 I am in the situation where I need to made some modifications to a content type in my .install file. I know how to create a content type programatically, just create it via the UI and export, and recreate the form to submit it.

But in this case deleting the existing content type and recreating it screws up the existing content type instances, so I need to add an existing field to an existing content type. Is that easy to do programatically?

Also what's up with Drupal's API or lack thereof to do these kinds of things? I'd love to do something like:

$foo_content_type = get_content_type('foo');
$foo_content_type-&gt;add_field( $the_field );


Why is this kind of stuff so bound to the UI? Is it just because of the historical development of Drupal? I'd say design the programatic API first, then bind the UI to that...
Is Drupal 7 much better?
Anything in the UI eventually has to call a function, so...  

The UI for editing a content type goes to path:

admin/content/node-type/NODETYPE


This path is "owned" by the cck module.  Looking in there, you can dig through the forms and hook_menu()s etc to see it eventually calls a function:

content_field_instance_create($field)


which is defined in

content.crud.inc


inside the cck module's inc directory.