field_attach_form not working as expected I created an entity like this:

&lt;?php
/**
* Implement hook_entity_info()
*/
function fy_teacher_entity_info()
{
    $entity['fy_teacher'] = array(
        'label' =&gt; t('teacher'),
        'controller class' =&gt; 'TeacherController',
        'base table' =&gt; 'fy_teacher',
        'uri callback' =&gt; 'fy_teacher_uri',
        'fieldable' =&gt; TRUE,
        'entity keys' =&gt; array(
            'label' =&gt; 'name',
            'id' =&gt; 'tid'
        ),
        'bundles' =&gt; array(
            'teacher' =&gt; array(
                'label' =&gt; t('teacher'),
                'admin' =&gt; array(
                    'path' =&gt; 'admin/structure/teachers',
                    'access arguments' =&gt; array('administer teachers')
                ),
            )
        ),
        'static cache' =&gt; TRUE,
        'view modes' =&gt; array(
            'full' =&gt; array(
                'label' =&gt; t('Full content'),
                'custom settings' =&gt; FALSE,
            ),
            'teaser' =&gt; array(
                'label' =&gt; t('Teaser'),
                'custom settings' =&gt; FALSE,
            ),
        ),
        'views controller class' =&gt; 'EntityDefaultViewsController',
    );
    return $entity;
}
?&gt;


And this is the form I created to add/edit this entity.

&lt;?php
/**
* teacher add/edit form
*/
function fy_teacher_form($form, &amp;$form_state, $teacher)
{
    $form_state['fy_teacher'] = $teacher;
    $form['name'] = array(
        '#type' =&gt; 'textfield',
        '#title' =&gt; t('Name'),
        '#default_value' =&gt; $teacher-&gt;name,
        '#weight' =&gt; '-5',
        '#required' =&gt; TRUE
    );

    field_attach_form('fy_teacher', $teacher, $form, $form_state);
    //Save button
    $form['buttons'] = array();
    $form['buttons']['#weight'] = 100;
    $form['buttons']['submit'] = array(
        '#type' =&gt; 'submit',
        '#value' =&gt; t('Save'),
        '#submit' =&gt; array('fy_teacher_form_submit')
    );

    // Delete button if on edit page
    if ($teacher-&gt;tid) {
        $form['buttons']['delete'] = array(
            '#access' =&gt; user_access('administer teachers'),
            '#type' =&gt; 'submit',
            '#value' =&gt; t('Delete'),
            '#submit' =&gt; array('fy_teacher_form_submit_delete')
        );
    }

    $form['#validate'][] = 'fy_teacher_form_validate';
    debug($form);
    return $form;
}
?&gt;


I can add fields in the backed (admin ui) of this entity. But somehow the fields I added there aren't showing up.
Turns out that the bundle name must be same as entity type.

&lt;?php
...
        'bundles' =&gt; array(
            'fy_teacher' =&gt; array(
                'label' =&gt; t('teacher'),
                'admin' =&gt; array(
                    'path' =&gt; 'admin/structure/teachers',
                    'access arguments' =&gt; array('administer teachers')
                ),
            )
        )
...
?&gt;


For anyone who has this issue,

In your hook_entity_info, under entity keys, simply add the bundle property.
to get the above example to work, simply change the entity keys array to :

&lt;?php
'entity keys' =&gt; array(
            'label' =&gt; 'name',
            'id' =&gt; 'tid',
            'bundle' =&gt; 'property_name' //The name of the property that contains the bundle name for the entity.
        ),
?&gt;


for hook entity info reference, see https://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_entity_info/7