title: Duplicating attribute in Magento
body: <p>What would be the proper way in Magento v1.4 to programmatically duplicate a (product) attribute? I'm fairly new to Magento and trying some things out to get to know it :)</p>
  
  <p>I've so far come up with the following,</p>
  
  <pre><code>$attribute = Mage::getModel('catalog/resource_eav_attribute')-&gt;load($id_of_attribute_to_copy);
  $data = $attribute-&gt;getData();
  $data['attribute_id'] = '';
  $data['attribute_code'] = 'new_attribute_name';
  $attribute-&gt;setData($data);
  $attribute-&gt;save();
  </code></pre>
  
  <p>but attributes seem to exist as a relation between two main tables, <code>eav_attribute</code> and <code>catalog_eav_attribute</code>. When I execute the code, only an entry for <code>catalog_eav_attribute</code> is created resulting in a Foreign Key error for <code>eav_attribute</code> (in which a new record doesn't yet exist). Hope someone can help.</p>