# Probleme beim Erstellen von Entities

**URL:** <https://forum.shopware.com/t/probleme-beim-erstellen-von-entities/65941>\
**Category:** Programmierung\
**Created:** [1. April 2020 um 16:54 UTC](https://forum.shopware.com/t/probleme-beim-erstellen-von-entities/65941 "2020-04-01T16:54:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Julian11](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@Julian11](https://forum.shopware.com/u/Julian11)\
**Post date:** [1. April 2020 um 16:54 UTC](https://forum.shopware.com/t/probleme-beim-erstellen-von-entities/65941/1 "2020-04-01T16:54:41Z")

</div>

Hallo liebe Community,

&nbsp;

ich habe mich mal an Shopware rangemacht und mir dazu die Academy Videos angeschaut. Dort scheitert es bei mir allerding bei dem Controller Video.&nbsp;  
An sich, einen Controller anlegen ist kein Problem, aber wenn ich darin, wie im Video mit dem Faker, Daten in die DB schreiben will, kommt es zum Problem.

Wenn es nur ein Datensatz ist, macht es keine Probleme solange noch kein Datensatz in dem Table ist.

Wenn ich mehrere gleichzeitig oder einzeln noch weitere Anlegen möchte, bekomme ich folgende Fehlermeldung:

```
{
  "errors": [
    {
      "status": "500",
      "code": "FRAMEWORK__WRITE_TYPE_INTEND_ERROR",
      "title": "Internal Server Error",
      "detail": "Expected command for "
      SwagShopFinder
      \
      \
      Core
      \
      \
      Content
      \
      \
      ShopFinder
      \
      \
      ShopFinderDefinition
      " to be "
      Shopware
      \
      \
      Core
      \
      \
      Framework
      \
      \
      DataAbstractionLayer
      \
      \
      Write
      \
      \
      Command
      \
      \
      InsertCommand
      ". (Got: Shopware\\Core\\Framework\\DataAbstractionLayer\\Write\\Command\\UpdateCommand)",
      "meta": {
        "parameters": {
          "definition": "SwagShopFinder\\Core\\Content\\ShopFinder\\ShopFinderDefinition",
          "expectedClass": "Shopware\\Core\\Framework\\DataAbstractionLayer\\Write\\Command\\InsertCommand",
          "actualClass": "Shopware\\Core\\Framework\\DataAbstractionLayer\\Write\\Command\\UpdateCommand"
        }
      }
    }
  ]
}

Response code: 500 (Internal Server Error); Time: 185ms; Content length: 672 bytes

```

&nbsp;

---

<div class="post-metadata">

**Author:** ![Julian11](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@Julian11](https://forum.shopware.com/u/Julian11)\
**Post date:** [2. April 2020 um 08:23 UTC](https://forum.shopware.com/t/probleme-beim-erstellen-von-entities/65941/2 "2020-04-02T08:23:09Z")

</div>

Okay ich konnte den Fehler selbst finden.  
Es war ein Fehler in der FieldCollection bei der EntityDefinition.

---

<div class="post-metadata">

**Author:** ![mfischer](https://avatars.discourse-cdn.com/v4/letter/m/82dd89/32.png) [@mfischer](https://forum.shopware.com/u/mfischer)\
**Post date:** [3. Mai 2020 um 19:29 UTC](https://forum.shopware.com/t/probleme-beim-erstellen-von-entities/65941/3 "2020-05-03T19:29:53Z")

</div>

Hallo @Julian11‍,

kannst du mir zufälligerweise sagen, was genau das Problem war? Bei meiner Entwicklung habe ich exakt das gleiche Verhalten. Vielen Dank im Voraus.

---

<div class="post-metadata">

**Author:** ![wolkenkrieger](https://avatars.discourse-cdn.com/v4/letter/w/85e7bf/32.png) [@wolkenkrieger](https://forum.shopware.com/u/wolkenkrieger)\
**Post date:** [8. August 2020 um 18:41 UTC](https://forum.shopware.com/t/probleme-beim-erstellen-von-entities/65941/4 "2020-08-08T18:41:19Z")

</div>

Für alle, die das auch so zum Kot\*en finden, wenn man zwar erklärt, dass man den Fehler gefunden hat aber dann selbst auf Nachfrage nicht mit seinem Geheimnis rausrückt:

Der Fehler wird (auch … bei mir war es jedenfalls genau das) ausgelöst, wenn man das IdField zwar auf Required aber nicht auf PrimaryKey setzt …

Muss also so aussehen:

&nbsp;

```
return new FieldCollection([
	(new IdField('id', 'id'))->addFlags(new Required(), new PrimaryKey())
]);

```

&nbsp;

---

<div class="post-metadata">

**Author:** ![shyim](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/shyim/32/7681_2.png) [@shyim](https://forum.shopware.com/u/shyim)\
**Post date:** [8. August 2020 um 19:54 UTC](https://forum.shopware.com/t/probleme-beim-erstellen-von-entities/65941/5 "2020-08-08T19:54:19Z")

</div>

./bin/console dal:validate ist auch ne gute Option 🙂

---

<div class="post-metadata">

**Author:** ![Kudze](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/kudze/32/18119_2.png) [@Kudze](https://forum.shopware.com/u/Kudze)\
**Post date:** [1. September 2022 um 10:14 UTC](https://forum.shopware.com/t/probleme-beim-erstellen-von-entities/65941/6 "2022-09-01T10:14:19Z")

</div>

The error could also be caused by missing created\_at and updated\_at fields in table.

---

<div class="post-metadata">

**Author:** ![clarusch](https://avatars.discourse-cdn.com/v4/letter/c/dec6dc/32.png) [@clarusch](https://forum.shopware.com/u/clarusch)\
**Post date:** [7. September 2024 um 10:47 UTC](https://forum.shopware.com/t/probleme-beim-erstellen-von-entities/65941/7 "2024-09-07T10:47:59Z")

</div>

Im Sinne einer Sammlung möglicher Fehlerquellen setzte ich dieses Topic einfach mal fort.

Bei mir war der Fehler ebenfalls in der EntityDefinition:

Ich hatte auch die Foreign Keys als Flag new PrimaryKey() mitgegeben:

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

```

Das ist natürlich Quatsch.

das commando

> [@shyim](#):
>
> ./bin/console dal:validate

hat mir den Fehler leider nicht angezeigt.
