# "Expected primary key field id for definition NameEntityDefinition not provided" bei insert

**URL:** <https://forum.shopware.com/t/expected-primary-key-field-id-for-definition-nameentitydefinition-not-provided-bei-insert/68809>\
**Category:** Programmierung\
**Created:** [6. August 2020 um 09:21 UTC](https://forum.shopware.com/t/expected-primary-key-field-id-for-definition-nameentitydefinition-not-provided-bei-insert/68809 "2020-08-06T09:21:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pomom](https://avatars.discourse-cdn.com/v4/letter/p/b5a626/32.png) [@pomom](https://forum.shopware.com/u/pomom)\
**Post date:** [6. August 2020 um 09:21 UTC](https://forum.shopware.com/t/expected-primary-key-field-id-for-definition-nameentitydefinition-not-provided-bei-insert/68809/1 "2020-08-06T09:21:13Z")

</div>

Hallo,

ich erstelle gerade in meinem Plugin eine eigene Entity, jedoch bekomme ich nun folgenden Fehler, wenn ich versuche neue Daten mittels “repository-\>create(…)” einzufügen:

“Expected primary key field id for definition PluginName\NameEntityDefinition not provided”

&nbsp;

Die “id” scheint also nicht gesetzt zu sein? Mein Code für den Insert sieht etwa so aus:

```
$this->clientRepository->create(
        [[
          "propertyA" => $data['a'],
          "propertyB"=> $data['b']
        ]],
        Context::createDefaultContext()
);

```

Ich habe nun jedoch auch einmal versucht, eine ID mitzugeben, dies ändert jedoch auch nichts.

```
$this->clientRepository->create(
        [[
          "id" => $this->gen_uuid(),
          "propertyA" => $data['a'],
          "propertyB"=> $data['b']
        ]],
        Context::createDefaultContext()
);

```

Meine Tabellen-Migration enthält dabei den Primary Key “id”:

```
CREATE TABLE IF NOT EXISTS `plugin_fast_clients` (
  `id` varchar(255) NOT NULL,
  `propertyA` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `propertyB` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

```

Was mache ich falsch, dass dieser Fehler auftritt?

---

<div class="post-metadata">

**Author:** ![pomom](https://avatars.discourse-cdn.com/v4/letter/p/b5a626/32.png) [@pomom](https://forum.shopware.com/u/pomom)\
**Post date:** [6. August 2020 um 12:00 UTC](https://forum.shopware.com/t/expected-primary-key-field-id-for-definition-nameentitydefinition-not-provided-bei-insert/68809/2 "2020-08-06T12:00:04Z")

</div>

Das Problem scheint in der Definition gewesen zu sein: Die Definition der ID muss&nbsp;

```
(new IdField('id', 'id'))->addFlags(new PrimaryKey(), new Required()),

```

lauten. Ich hatte vorher jedoch nur&nbsp;

```
(new IdField('id', 'id'))->addFlags(new PrimaryKey()),

```

genutzt
