2

I using Sonata Admin bundle. I get error: Failed to create object: PizzaBundle\Entity\Promotion. I did a Promotion entity:

/**
 * @ORM\Entity
 * @ORM\Table(name="promotion")
 */
class Promotion {

    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=100)
     */
    private $title;

    /**
     * @ORM\Column(type="string")
     */
    private $description;



    /**
     * @ORM\Column(type="blob")
     */
    private $image;

    /**
     * @ORM\Column(type="date")
     */
    private $dataStart;

    /**
     * @ORM\Column(type="date")
     */
    private $dataEnd;

And PromotionAdmin.php

public function configureFormFields(FormMapper $formMapper) {
        $formMapper
                ->add('title', 'text')
                ->add('description', 'text')
                ->end()
                ->with('Zdjęcie')
                    ->add('image', 'file', ['required' => false]) 
                    ->add('dataStart', 'date')
                    ->add('dataEnd', 'date')
                ->end();
    }

    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
    {
        $datagridMapper
                ->add('title')
                ->add('description')
                ->add('image')
                ->add('dataStart')
                ->add('dataEnd')
                ;
    }

    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
                ->addIdentifier('title')
                ->addIdentifier('description')
                ->addIdentifier('image')
                ->addIdentifier('dataStart')
                ->addIdentifier('dataEnd')
                ;
    }



}

My services.yml

admin.promotion:
        class: PizzaBundle\Admin\PromotionAdmin
        arguments: [~, PizzaBundle\Entity\Promotion, ~]
        tags:
            - { name: sonata.admin, manager_type: orm, label: Promotion }

I don't have a problem with my code. I think that this is problem with type variable Image in entity. If this is error in type blob, please help resolve problem.

2
  • There should be a log line with an exception, have a look in the profiler. Commented May 3, 2017 at 9:43
  • My post about Exception is down. Commented May 3, 2017 at 11:27

1 Answer 1

2

You are trying to insert NULL into the "image" column, which is not nullable it seems, which results in an MySQL error.

/**
 * @ORM\Entity
 * @ORM\Table(name="promotion")
 */
class Promotion 
{
     /**
      * @ORM\Column(type="blob", nullable=true)
      */
     private $image;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.