Column Not Added to Table in Database Despite Executing php bin/console doctrine:schema:update –complete –force Command
The command php bin/console doctrine:schema:update --force
is indeed generating entities with fields. However, when I attempted to add a field to an existing entity, it didn’t work as expected. Despite the command being successful in creating initial entities and their fields, it seems to encounter issues when trying to modify existing entities by adding new fields. I’m facing difficulties in updating the schema with additional fields for pre-existing entities.
doctrine.yaml
doctrine:
dbal:
driver: pdo_mysql
host: '%database_host%'
port: '%database_port%'
dbname: '%database_name%'
user: '%database_user%'
password: '%database_password%'
# only needed for MySQL
charset: utf8mb4
default_table_options:
collate: utf8mb4_unicode_ci
mapping_types:
enum: string
server_version: 5.7
# Pour changer le mode sql pour supporter le NONE_FULL_GROUP_BY pour les requêtes sql
options:
1002: 'SET sql_mode=(SELECT REPLACE(@@sql_mode, "ONLY_FULL_GROUP_BY", ""))'
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: '%kernel.project_dir%/var/data/data.sqlite'
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
#path: '%database_path%'
orm:
auto_generate_proxy_classes: false
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
dql:
string_functions:
WEEK: DoctrineExtensionsQueryMysqlWeek
MONTH: DoctrineExtensionsQueryMysqlMonth
YEAR: DoctrineExtensionsQueryMysqlYear
datetime_functions:
TimestampDiff: DoctrineExtensionsQueryMysqlTimestampDiff
mappings:
App:
is_bundle: false
dir: '%kernel.project_dir%/src/Entity'
prefix: 'AppEntity'
alias: App
when@test:
doctrine:
dbal:
# "TEST_TOKEN" is typically set by ParaTest
dbname_suffix: '_test%env(default::TEST_TOKEN)%'
when@prod:
doctrine:
orm:
auto_generate_proxy_classes: false
query_cache_driver:
type: pool
pool: doctrine.system_cache_pool
result_cache_driver:
type: pool
pool: doctrine.result_cache_pool
framework:
cache:
pools:
doctrine.result_cache_pool:
adapter: cache.app
doctrine.system_cache_pool:
adapter: cache.system
entity:
<?php
namespace AppEntity;
use DoctrineCommonCollectionsArrayCollection;
use DoctrineCommonCollectionsCollection;
use DoctrineDBALTypesTypes;
use DoctrineORMMapping as ORM;
/**
* Incident_collecte
*
* @author Alaa
*
* @ORMTable(name="incident_collecte")
* @ORMEntity(repositoryClass="AppRepositoryIncidentCollecteRepository")
*
*/
class IncidentCollecte
{
---------
/**
* @ORMColumn(type="array", nullable=true)
*
* Table des meta-données d'un incident qui permet sa gestion, comme son état précédent
**/
private $metaData;
#[ORMColumn(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?DateTimeInterface $UpdatedDateStatutFromPortal = null;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set dateCreation
*
* @param DateTime $dateCreation
*
* @return IncidentCollecte
*/
public function setDateCreation($dateCreation)
{
$this->date_creation = $dateCreation;
return $this;
}
/**
* Get dateCreation
*
* @return DateTime
*/
public function getDateCreation()
{
return $this->date_creation;
}
/**
* Set description
*
* @param string $description
*
* @return IncidentCollecte
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set idDemande.
*
* @param int $idDemande
*
* @return IncidentCollecte
*/
public function setIdDemande($idDemande)
{
$this->id_demande = $idDemande;
return $this;
}
/**
* Get idDemande.
*
* @return int
*/
public function getIdDemande()
{
return $this->id_demande;
}
/**
* Set dateCloture.
*
* @param DateTime|null $dateCloture
*
* @return IncidentCollecte
*/
public function setDateCloture($dateCloture = null)
{
$this->date_cloture = $dateCloture;
return $this;
}
/**
* Get dateCloture.
*
* @return DateTime|null
*/
public function getDateCloture()
{
return $this->date_cloture;
}
/**
* Set typeDemande.
*
* @param string|null $typeDemande
*
* @return IncidentCollecte
*/
public function setTypeDemande($typeDemande = null)
{
$this->type_demande = $typeDemande;
return $this;
}
/**
* Get typeDemande.
*
* @return string|null
*/
public function getTypeDemande()
{
return $this->type_demande;
}
/**
* Set cleDemande.
*
* @param string $cleDemande
*
* @return IncidentCollecte
*/
public function setCleDemande($cleDemande)
{
$this->cle_demande = $cleDemande;
return $this;
}
/**
* Get cleDemande.
*
* @return string
*/
public function getCleDemande()
{
return $this->cle_demande;
}
/**
* Set raisonCloture.
*
* @param string|null $raisonCloture
*
* @return IncidentCollecte
*/
public function setRaisonCloture($raisonCloture = null)
{
$this->raison_cloture = $raisonCloture;
return $this;
}
/**
* Get raisonCloture.
*
* @return string|null
*/
public function getRaisonCloture()
{
return $this->raison_cloture;
}
/**
* Set priorite.
*
* @param string $priorite
*
* @return IncidentCollecte
*/
public function setPriorite($priorite)
{
$this->priorite = $priorite;
return $this;
}
/**
* Get priorite.
*
* @return string
*/
public function getPriorite()
{
return $this->priorite;
}
/**
* Set etat.
*
* @param string $etat
*
* @return IncidentCollecte
*/
public function setEtat($etat)
{
$this->etat = $etat;
return $this;
}
/**
* Get etat.
*
* @return string
*/
public function getEtat()
{
return $this->etat;
}
/**
* Set regle.
*
* @param string|null $regle
*
* @return IncidentCollecte
*/
public function setRegle($regle = null)
{
$this->regle = $regle;
return $this;
}
/**
* Get regle.
*
* @return string|null
*/
public function getRegle()
{
return $this->regle;
}
/**
* Set DatePriseEnCompteClient.
*
* @param DateTime|null $datePriseEnCompteClient
*
* @return IncidentCollecte
*/
public function setDatePriseEnCompteClient($dateMajClient = null)
{
$this->date_prise_en_compte_client = $dateMajClient;
return $this;
}
/**
* Get DatePriseEnCompteClient.
*
* @return DateTime|null
*/
public function getDatePriseEnCompteClient()
{
return $this->date_prise_en_compte_client;
}
/**
* Set impact.
*
* @param string|null $impact
*
* @return IncidentCollecte
*/
public function setImpact($impact = null)
{
$this->impact = $impact;
return $this;
}
/**
* Get impact.
*
* @return string|null
*/
public function getImpact()
{
return $this->impact;
}
/**
* @return Collection|Siiv[]
*/
public function getSiiv(): Collection
{
return $this->siiv;
}
public function addSiiv(Siiv $siiv): self
{
if (!$this->siiv->contains($siiv)) {
$this->siiv[] = $siiv;
}
return $this;
}
public function removeSiiv(Siiv $siiv): self
{
$this->siiv->removeElement($siiv);
return $this;
}
/**
* Set collecteurLogs.
*
* @param string|null $collecteurLogs
*
* @return IncidentCollecte
*/
public function setCollecteurLogs($collecteurLogs = null)
{
$this->collecteur_logs = $collecteurLogs;
return $this;
}
/**
* Get collecteurLogs.
*
* @return string|null
*/
public function getCollecteurLogs()
{
return $this->collecteur_logs;
}
/**
* Set metaData.
*
* @param array|null $metaData
*
* @return IncidentCollecte
*/
public function setMetaData($metaData = null)
{
$this->metaData = $metaData;
return $this;
}
/**
* Get metaData.
*
* @return array|null
*/
public function getMetaData()
{
return $this->metaData;
}
/**
* @return string|null
*/
public function getNumoffense(): ?string
{
return $this->numoffense;
}
/**
*
* @param string|null $numoffense
* @return IncidentCollecte
*/
public function setNumoffense(?string $numoffense): IncidentCollecte
{
$this->numoffense = $numoffense;
return $this;
}
/**
* @return string|null
*/
public function getSeverity(): ?string
{
return $this->severity;
}
/**
* @param string|null $severity
* @return IncidentCollecte
*/
public function setSeverity(?string $severity): IncidentCollecte
{
$this->severity = $severity;
return $this;
}
public function getUpdatedDateStatutFromPortal(): ?DateTimeInterface
{
return $this->UpdatedDateStatutFromPortal;
}
public function setUpdatedDateStatutFromPortal(?DateTimeInterface $UpdatedDateStatutFromPortal): static
{
$this->UpdatedDateStatutFromPortal = $UpdatedDateStatutFromPortal;
return $this;
}
}
2
Answers
Did you try to use only annotations instead of mixing annotations and PHP attributes ?
Check here for more details: How can i use php8 attributes instead of annotations in doctrine?
Since this a Symfony project, you might also want to consider using DoctrineMigrationsBundle which is provided by Symfony a much faster, easier and safer way to implement changes to your database schema. While you’re at it, you also might want to consider the the Symfonyt Maker Bundle that also make creating and/or adding to your existing entity schemas much easier. It handles all of the dirty work of creating the correct annotations, as well as handles any relational tables you might have.