Create custom entity type programmatically maybe my title is not correct but I have written a module that creates a new entity. Now I would like to create a few of these entities on hook_install. I can create a new entity, that's not the problem, but I cannot create the entity types.

This is my code I use to create a new entity:

/**
 * Implements hook_install()
 */
function skilt_badge_install(){
  $entity = entity_create('skilt_badge', array('type' =&gt;'test'));
  $entity-&gt;title = "Testtitle";
  $entity-&gt;description = "Testdescription";
  $entity-&gt;save();
}


Now, when I create a new Skilt badge type with the machine name "test" in the drupal interface it works. But first I would like to know how I create the Skilt badge type programmatically.

I've tried something like this first, thinking the type is also an entity:

/**
 * Implements hook_install()
 */
function skilt_badge_install(){
  $entity = entity_create('skilt_badge_type');
  $entity-&gt;title = "Testtitle";
  $entity-&gt;description = "Testdescription";
  $entity-&gt;save();
}


But that didn't really work because entity create requires a type...

Could you guys help me?
As some have commented, Entities are VERY complicated. The reason your code is not working is because entity_create() is used to create an INSTANCE of an entity of an already defined entity type. What you are doing in the UI creates the entity type.

You must first create your entity type in your module before you can create an instance of that entity. Refer to the links in the comments above on how to do this. And get ready to spend a little time if this is your first time doing this -I assume it is.