SonataMediaBundle: Duplicate entry for primary key

Environment

Sonata packages

sonata media bundle 3.0.0 sonata classification bundle 3.0.0 some other not related to this issue

$ composer show sonata-project/*
sonata-project/admin-bundle              3.0.0              The missing Symfony Admin Generator
sonata-project/block-bundle              3.0.1              Symfony SonataBlockBundle
sonata-project/cache                     1.0.7              Cache library
sonata-project/cache-bundle              dev-master 76e4ff6 This bundle provides caching services
sonata-project/classification-bundle     3.0.0              Symfony SonataClassificationBundle
sonata-project/core-bundle               3.0.3              Symfony SonataCoreBundle
sonata-project/datagrid-bundle           2.2                Symfony SonataDatagridBundle
sonata-project/doctrine-extensions       1.0.2              Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.0.0              Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/easy-extends-bundle       2.1.10             Symfony SonataEasyExtendsBundle
sonata-project/exporter                  1.5.0              Lightweight Exporter library
sonata-project/intl-bundle               2.2.4              Symfony SonataIntlBundle
sonata-project/media-bundle              3.0.0              Symfony SonataMediaBundle
sonata-project/notification-bundle       3.0.0              Symfony SonataNotificationBundle

Symfony packages

$ composer show symfony/*
symfony/assetic-bundle     v2.7.0             Integrates Assetic into Symfony2
symfony/monolog-bundle     v2.7.1             Symfony MonologBundle
symfony/phpunit-bridge     dev-master f5925bc Symfony PHPUnit Bridge
symfony/polyfill-apcu      v1.1.1             Symfony polyfill backporting apcu_* functions to lower PHP versions
symfony/swiftmailer-bundle v2.3.8             Symfony SwiftmailerBundle
symfony/symfony            v2.7.10            The Symfony PHP framework

PHP version

$ php -v
PHP 7.0.7-4+deb.sury.org~xenial+1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

Subject

Upload a media via sonata media bundle using sonata classification bundle

Steps to reproduce

That could depend on my project wich is really awkward. I use the standard upload form provided by the bundle with two fields : file and category. I set an image in the first field and use an existing category for the second field

Expected results

New media created related to the classification context. classification context ‘news’ already exist and should not be created. New media should be associated to the existing context ‘news’.

Actual results

An exception occurred while executing ‘INSERT INTO classification__context (name, enabled, created_at, updated_at, id) VALUES (?, ?, ?, ?, ?)’ with params [“news”, 1, “2016-06-22 13:28:00”, “2016-06-22 13:28:00”, “news”]:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ‘news’ for key ‘PRIMARY’

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 18 (9 by maintainers)

Most upvoted comments

Glad you managed to find a solution!

Un use step by step. I use it for the first time. Very usefull, I will use it more often ! I hope I read the debug correctly but aparently the entity Category is detected as new entity insteand of managed. I tested the same process with my fr sub environment and Category is detected as managed entity.

I have created multiple sub environment depending on the locale (sorry about that previous version was worth than that, thank you previous dev) : fr, pl, ua, en. Each sub env has its own cache dir : fr_prod, pl_prod… and its own configuration : app/config/fr/parameters.yml, app/config/fr/config.yml to override or not common configuration : app/config/config.yml (same for dev and prod envs) There is a common database ‘intl’ for all common data and one database per locale : fr, pl, ua, en. Medias are stored in the localized databases.

Media creation works fine with for fr locale but the error occurs with pl. Context ‘news’ is identical in both of them. Not tested with the other locales.

Sorry about the architecture. I am doing my best to restructur all the stuff correctly !

classification context ‘news’ already exist and should not be created. New media should be associated to the existing context ‘news’