执行&INSERT INTO用户(vUsername,vEmail,vPassword,vUserPic,dCreatedDate,dModifiedDate)VALUES(?,?,?,?,?,?)' with params [null,null,null,null,null,null]:
SQLSTATE [23000]:完整性约束违规:1048列' vUsername'当我将数据插入表
时,在symfony中不能为nullINFO - Matched route "app_user_users".
INFO - Populated the TokenStorage with an anonymous Token.
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::configure".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\DumpListener::configure".
DEBUG - Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\FragmentListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\TranslatorListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\Security\Http\Firewall::onKernelRequest".
DEBUG - Notified event "kernel.controller" to listener "Symfony\Bundle\FrameworkBundle\DataCollector\RouterDataCollector::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Symfony\Component\HttpKernel\DataCollector\RequestDataCollector::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ControllerListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ParamConverterListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\HttpCacheListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\SecurityListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener::onKernelController".
DEBUG - "START TRANSACTION"
DEBUG - INSERT INTO users (vUsername, vEmail, vPassword, vUserPic, dCreatedDate, dModifiedDate) VALUES (?, ?, ?, ?, ?, ?)
DEBUG - "ROLLBACK"
CRITICAL - Uncaught PHP Exception Doctrine\DBAL\Exception\NotNullConstraintViolationException: "An exception occurred while executing 'INSERT INTO users (vUsername, vEmail, vPassword, vUserPic, dCreatedDate, dModifiedDate) VALUES (?, ?, ?, ?, ?, ?)' with params [null, null, null, null, null, null]: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'vUsername' cannot be null" at /opt/lampp/htdocs/userpost/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php line 112
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::configure".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\DumpListener::configure".
DEBUG - Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\FragmentListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\TranslatorListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\Security\Http\Firewall::onKernelRequest".
DEBUG - Notified event "kernel.controller" to listener "Symfony\Bundle\FrameworkBundle\DataCollector\RouterDataCollector::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Symfony\Component\HttpKernel\DataCollector\RequestDataCollector::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ControllerListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ParamConverterListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\HttpCacheListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\SecurityListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener::onKernelController".
<?php
namespace AppBundle\Controller;
use AppBundle\Form\UsersType;
use AppBundle\Entity\Users;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
class UserController extends Controller
{
/**
* @Route("/users")
*/
public function usersAction(Request $request)
{
$users = new Users();
$form = $this->createForm(UsersType::class, $users);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($users);
$em->flush();
return $this->redirectToRoute('register.html.twig');
}
return $this->render(
'UserRegistration/register.html.twig',
array('form' => $form->createView())
);
}
}
<?php
namespace AppBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class UsersType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('vUsername')
->add('vEmail')
->add('vPassword')
->add('vUserPic');
}
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'AppBundle\Entity\Users'
));
}
}
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Users
*
* @ORM\Table(name="users")
* @ORM\Entity(repositoryClass="AppBundle\Repository\UsersRepository")
*/
class Users
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="vUsername", type="string", length=255, nullable=true)
*/
private $vUsername;
/**
* @var string
*
* @ORM\Column(name="vEmail", type="string", length=255, nullable=true)
*/
private $vEmail;
/**
* @var string
*
* @ORM\Column(name="vPassword", type="string", length=32, nullable=true)
*/
private $vPassword;
/**
* @var string
*
* @ORM\Column(name="vUserPic", type="string", length=255, nullable=true)
*/
private $vUserPic;
/**
* @var \DateTime
*
* @ORM\Column(name="dCreatedDate", type="datetime", nullable=true)
*/
private $dCreatedDate;
/**
* @var \DateTime
*
* @ORM\Column(name="dModifiedDate", type="datetime", nullable=true)
*/
private $dModifiedDate;
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set vUsername
*
* @param string $vUsername
*
* @return Users
*/
public function setVUsername($vUsername)
{
$this->vUsername = $vUsername;
return $this;
}
/**
* Get vUsername
*
* @return string
*/
public function getVUsername()
{
return $this->vUsername;
}
/**
* Set vEmail
*
* @param string $vEmail
*
* @return Users
*/
public function setVEmail($vEmail)
{
$this->vEmail = $vEmail;
return $this;
}
/**
* Get vEmail
*
* @return string
*/
public function getVEmail()
{
return $this->vEmail;
}
/**
* Set vPassword
*
* @param string $vPassword
*
* @return Users
*/
public function setVPassword($vPassword)
{
$this->vPassword = $vPassword;
return $this;
}
/**
* Get vPassword
*
* @return string
*/
public function getVPassword()
{
return $this->vPassword;
}
/**
* Set vUserPic
*
* @param string $vUserPic
*
* @return Users
*/
public function setVUserPic($vUserPic)
{
$this->vUserPic = $vUserPic;
return $this;
}
/**
* Get vUserPic
*
* @return string
*/
public function getVUserPic()
{
return $this->vUserPic;
}
/**
* Set dCreatedDate
*
* @param \DateTime $dCreatedDate
*
* @return Users
*/
public function setDCreatedDate($dCreatedDate)
{
$this->dCreatedDate = $dCreatedDate;
return $this;
}
/**
* Get dCreatedDate
*
* @return \DateTime
*/
public function getDCreatedDate()
{
return $this->dCreatedDate;
}
/**
* Set dModifiedDate
*
* @param \DateTime $dModifiedDate
*
* @return Users
*/
public function setDModifiedDate($dModifiedDate)
{
$this->dModifiedDate = $dModifiedDate;
return $this;
}
/**
* Get dModifiedDate
*
* @return \DateTime
*/
public function getDModifiedDate()
{
return $this->dModifiedDate;
}
/**
* @var string
*/
private $vusername;
/**
* @var string
*/
private $vemail;
/**
* @var string
*/
private $vpassword;
/**
* @var string
*/
private $vuserpic;
/**
* @var \DateTime
*/
private $dcreateddate;
/**
* @var \DateTime
*/
private $dmodifieddate;
}
答案 0 :(得分:0)
也许您将用户名更改为可以为空并忘记更新数据库架构(d:s:u --force)。