开发者

Integrity constraint violation Doctrine 2 and Symfony

I'm having some sort of textbuilder where you can add blocks to bu开发者_Go百科ild up your text. The building blocks are defined in the database and when you add 1 to your text, it gets saved in the session (how you build them up).

But now when I try to persist the session to the database I get an:

Integrity constraint violation: 1062 Duplicate entry 'text' for key 'UNIQ_AA5F49C77153098'

He wants to add the existing definition of the building block, but it is already defined. The session itself is serialized.

So the steps that I'm doing to save is:

1) deserialize ( I also tried to merge it, but that didn't work either.)

2) persist to database => error


Instead of persisting the unserialized object directly, do that: - unserialize the object - fetch the object from database - update the retrieved object with the value of the unserialized one - persist the retrieved object

Does it work ?


Maybe you're using the wrong association type for your model. I don't remember clearly but Doctrine adds a unicity constraints to unidirectional many to many or one to one associations.


I had a similar problem with FOSUserBundle: I am not sure how to override the mapping configuration of an extended entity (in my case the field email_canonical, which was not used, but two empty fields also triggered the integrity violation).

I ended up with manually deleting the constraint in the database (and with app/console doctrine:schema:update --dump-sql only updating the changes with the SQL command - except the UNIQUE Constraint)

As pointed out by futurecat: do you need your "text" field to be unique?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜