dustin10 / VichUploaderBundle

A simple Symfony bundle to ease file uploads with ORM entities and ODM documents.
MIT License
1.84k stars 520 forks source link

VichUploaderBundle (Column 'image_name' cannot be null) ! #439

Closed 01sup closed 9 years ago

01sup commented 9 years ago

I have in my project an entity "Article", and i followed all the steps to add a file selector to this entity form but I get this error I dont know why :

An exception occurred while executing 'INSERT INTO article (titre, contenu, date, image_name, updated_at, professeur_id) VALUES (?, ?, ?, ?, ?, ?)' with params ["sdfsd", "sdfdsfdsvsd dsfds fsd", "2015-08-28", null, "2015-08-28 02:56:57", 70]:

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'image_name' cannot be null

K-Phoen commented 9 years ago

There is probably an error in your mapping or in the form definition. Could you paste these two classes here?

01sup commented 9 years ago

<?php

namespace ENSA\PortailWebLaboratoireBundle\Entity;

use Doctrine\ORM\Mapping as ORM; use Symfony\Component\HttpFoundation\File\File; use Vich\UploaderBundle\Mapping\Annotation as Vich;

/**

}

K-Phoen commented 9 years ago

It seems that you forgot to add the @Vich\Uploadable annotation to your class, as specified in the documentation.

01sup commented 9 years ago

nn actually I dont forget it I deleted the entity yesterday and I forget to add this annoation today so this is not the problem, I'm getting the same error even with the annotation !

K-Phoen commented 9 years ago

Probably a cache issue then. Once the entity is properly configured, you have to clear the cache.

01sup commented 9 years ago

I cleared the cache also (cache:clear) so this is not the problem !

01sup commented 9 years ago

should i use 2 entities one for the Article and the other for storing the file !!!

Or there is somthing wrong with this line of code : @Vich\UploadableField(mapping="product_image", fileNameProperty="imageName") *

because I dont know what mapping="product_image" means and what it's relation with my article entity !!!

01sup commented 9 years ago

And this my config.yml configuration :

app/config/config.yml

vich_uploader: db_driver: orm

mappings:
    espace_partage:
        uri_prefix:         /documents
        upload_destination: %kernel.root_dir%/../web/documents
        inject_on_load:     false
        delete_on_update:   true
        delete_on_remove:   true

I created a folder named documents in the web folder of symfony !

01sup commented 9 years ago

update : I changed the attribute mapping to "espace_partage" and the error is not shwon anymore but nothing is added to the database !!!

01sup commented 9 years ago

UPDATE : I figure out that this issue have a relation with the size of the file (I think around 3Mo), so now I want to allow anay size of files !

acorbel commented 9 years ago

maybe related to #442

01sup commented 9 years ago

YAA I foget to close this issue; tnx again :)