I'm currently working on a project for planning transports between different destinations. Therefore I'm using Symfony 3.3.
I've created a form which is working perfectly in my development environment but crashes on my production platform.
The form consists of the main Form (transportFormType.php) and an included subform (truckFormType.php) which you can both see attached. The form is properly added in TwigFile (_form.html.twig).
In my development environment, after filling out the form I'm able to save it and it gets saved to the database. After deploying the project on my production server I also can see the regular form and fill it with content, but after clicking "Save" nothing happens and my prod-logs speak of missing columns.
Does anybody know my fault?
Thanks!
The log message:
request.CRITICAL: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'content' cannot be null" at /... line 112 {"exception":"[object] (Doctrine\DBAL\Exception\NotNullConstraintViolationException(code: 0): An exception occurred while executing 'INSERT INTO truck (trucktype, carrier, booked, content, loading_time, license_plate, driver_name, checkin, checkout, delivery_time, shift_start, steeringtime, netto_steering_time_in_seconds, gros_drive_time_in_seconds_with_driver, check_out_information, priority, transport_id, booker_id, check_in_by_id, check_out_by_id, loading_place_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' with params [\"7,5t Koffer\", null, null, null, null, null, null, null, null, null, null, null, null, null, null, 0, 1, null, null, null, 1]:\n\nSQLSTATE[23000]: Integrity constraint violation: 1048 Column 'content' cannot be null at /www/htdocs/w01759ff/www/disponentMe/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:112, Doctrine\DBAL\Driver\PDOException(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'content' cannot be null at /.../lib/Doctrine/DBAL/Driver/PDOStatement.php:107, PDOException(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'content' cannot be null at /www/.../lib/Doctrine/DBAL/Driver/PDOStatement.php:105)"} []
TransportFomType.php:
$builder
->add('origin', EntityType::class, [
'class' => 'AppBundle\Entity\Address',
'choice_label' => 'station',
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('a')
->where('a.isStation = true');
},
'attr' => [
'onchange' => "filterLoadingPlaces()"
],
])
->add('destination', AddressFormType::class)
->add('trucks', CollectionType::class, [
'entry_type' => TruckFormType::class,
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
]);
TruckFormType.php:
$builder
->add('content')
->add('loadingPlace', EntityType::class, [
'class' => 'AppBundle\Entity\LoadingPlace',
'choice_label' => 'name',
'choice_attr' => function(LoadingPlace $place, $key, $index) {
return ['station' => $place->getAddress()->getId()];
},
'attr' => [
'class' => "loadingPlace",
]
])
->add('trucktype', ChoiceType::class, [
'choices' => [
'7,5t Koffer' => '7,5t Koffer',
'Sattel mit Plane' => 'Sattel mit Plane',
'Sattel mit Koffer' => 'Sattel mit Koffer',
'Sattel mit Plattform' => 'Sattel mit Plattform',
]
])
->add('deliveryTime', DateTimeType::class, [
'widget' => 'single_text',
'html5' => false,
'attr' => ['class' => 'js-datepicker'],
'format' => 'dd.MM.yyyy hh:mm',
])
;
_form.html.twig:
{% import _self as formMacros %}
{% macro printTruckRow(truckFormType) %}
<div class="js-truck-item row" style="padding-bottom: 10px;">
<div>{{ form_widget(truckFormType.content) }}</div>
<div>{{ form_widget(truckFormType.loadingPlace) }}</div>
<div>{{ form_widget(truckFormType.trucktype) }}</div>
<div>{{ form_widget(truckFormType.deliveryTime) }}</div>
<div class="removeTruck"><a class="js-remove-truck btn btn-danger pull-right" href="#"><i class="fa fa-close"></i></a></div>
</div>
{% endmacro %}
{{ form_start(transportForm) }}
{{ form_errors(transportForm) }}
<div class="container-fluid">
<div class="row">
<div>
{{ form_row(transportForm.origin) }}
</div>
<div>
{{ form_row(transportForm.destination.station) }}
</div>
<div>
{{ form_row(transportForm.destination.street) }}
</div>
<div>
{{ form_row(transportForm.destination.postalnumber) }}
</div>
<div>
{{ form_row(transportForm.destination.city) }}
</div>
<div>
{{ form_row(transportForm.destination.country) }}
</div>
</div>
<div class="js-trucks-wrapper" data-prototype="{{ formMacros.printTruckRow(transportForm.trucks.vars.prototype)|e('html_attr') }}" data-index="{{ transportForm.trucks|length }}">
<div>Content</div>
<div>Loadingdock</div>
<div>Trucktype</div>
<div>DeliveryTime</div>
<div></div>
{% for truck in transportForm.trucks %}
{{ formMacros.printTruckRow(truck) }}
{% endfor %}
<a href="#" class="btn btn-success js-add-truck" style="margin-top: 10px"><i class="fa fa-plus"></i> {{ 'transport.button.addTruck'|trans() }}</a>
</div>
<button type="submit" class="btn btn-primary" formnovalidate>{{ 'transport.button.save'|trans() }}</button>
{{ form_end(transportForm) }}
</div>
Controller Function:
public function newAction(Request $request) {
$transport = new Transport();
$truck = new Truck();
$transport->addTruck($truck);
$transport->setOrderer($this->get('security.token_storage')->getToken()->getUser());
$transport->setIsReturn(false);
$form = $this->createForm(TransportFormType::class, $transport);
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($form->getData());
$em->flush();
$this->addFlash('success','Transport created.');
return $this->redirectToRoute('open_transport_list');
}
return $this->render(':transport:newTransport.html.twig', ['transportForm' => $form->createView()]);
}
And the Entity Class of Truck (without getters and setters):
/**
* @ORM\Entity(repositoryClass="AppBundle\Repository\TruckRepository")
* @ORM\Table(name="truck")
*/
class Truck
{
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="Transport", inversedBy="trucks")
* @ORM\JoinColumn()
*/
private $transport;
/**
* @ORM\ManyToOne(targetEntity="User")
*/
private $booker;
/**
* @ORM\ManyToOne(targetEntity="User")
*/
private $checkInBy;
/**
* @ORM\ManyToOne(targetEntity="User")
*/
private $checkOutBy;
/**
* @ORM\Column(type="string")
*/
private $trucktype;
/**
* @ORM\Column(type="string",nullable=true)
*/
private $carrier;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $booked;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $content;
/**
* @ORM\ManyToOne(targetEntity="LoadingPlace")
*/
private $loadingPlace;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $loadingTime;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $licensePlate;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $driverName;
/**
* @ORM\Column(type="datetime",nullable=true)
*/
private $checkin;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $checkout;
/**
* TODO Sicherstellen, dass Datum neuer als NOW() ist.
* @ORM\Column(type="datetime")
*/
private $deliveryTime;
/**
* TODO Sicherstellen, dass Datum älter als NOW() ist.
* @ORM\Column(type="datetime", nullable=true)
*/
private $shiftStart;
/**
* Lenkzeit in Minuten
* @ORM\Column(type="integer", nullable=true)
* @Assert\Range(min=0, minMessage="Negative Lenkzeiten gibt es nicht.")
* @Assert\Range(max=36000, maxMessage="Mehr als 10 Stunden Lenkzeiten sind nicht erlaubt." )
*/
private $steeringtime;
/**
* @ORM\Column(type="integer",nullable=true)
*/
private $nettoSteeringTimeInSeconds;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $grosDriveTimeInSecondsWithDriver;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $checkOutInformation;
/**
* @ORM\Column(type="integer")
*/
private $priority = 0;
php bin/console doctrine:schema:update --force- Robert Wade