Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

doctrine:schema:update error There is no column with name '$column' on table '$table'

I've made some changes to my doctrine Entities and need to update the database and got the following error.

$ php bin/console doctrine:schema:update -vvv


  [Doctrine\DBAL\Schema\SchemaException (30)]                   
  There is no column with name 'fleet_no' on table 'fuelData'.  


Exception trace:
 () at /home/sarah/workspace/telematics_tracker/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/SchemaException.php:86
 Doctrine\DBAL\Schema\SchemaException::columnDoesNotExist() at /home/sarah/workspace/telematics_tracker/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Table.php:671
 Doctrine\DBAL\Schema\Table->getColumn() at /home/sarah/workspace/telematics_tracker/vendor/doctrine/dbal/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php:711
 Doctrine\DBAL\Platforms\MySqlPlatform->getPreAlterTableAlterPrimaryKeySQL() at /home/sarah/workspace/telematics_tracker/vendor/doctrine/dbal/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php:639
 Doctrine\DBAL\Platforms\MySqlPlatform->getPreAlterTableIndexForeignKeySQL() at /home/sarah/workspace/telematics_tracker/vendor/doctrine/dbal/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php:621
 Doctrine\DBAL\Platforms\MySqlPlatform->getAlterTableSQL() at /home/sarah/workspace/telematics_tracker/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/SchemaDiff.php:199
 Doctrine\DBAL\Schema\SchemaDiff->_toSql() at /home/sarah/workspace/telematics_tracker/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/SchemaDiff.php:126
 Doctrine\DBAL\Schema\SchemaDiff->toSaveSql() at /home/sarah/workspace/telematics_tracker/vendor/doctrine/orm/lib/Doctrine/ORM/Tools/SchemaTool.php:883
 Doctrine\ORM\Tools\SchemaTool->getUpdateSchemaSql() at /home/sarah/workspace/telematics_tracker/vendor/doctrine/orm/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/UpdateCommand.php:115
 Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand->executeSchemaCommand() at /home/sarah/workspace/telematics_tracker/vendor/doctrine/orm/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/AbstractCommand.php:65
 Doctrine\ORM\Tools\Console\Command\SchemaTool\AbstractCommand->execute() at /home/sarah/workspace/telematics_tracker/vendor/doctrine/doctrine-bundle/Command/Proxy/UpdateSchemaDoctrineCommand.php:50
 Doctrine\Bundle\DoctrineBundle\Command\Proxy\UpdateSchemaDoctrineCommand->execute() at /home/sarah/workspace/telematics_tracker/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:261
 Symfony\Component\Console\Command\Command->run() at /home/sarah/workspace/telematics_tracker/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:839
 Symfony\Component\Console\Application->doRunCommand() at /home/sarah/workspace/telematics_tracker/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:185
 Symfony\Component\Console\Application->doRun() at /home/sarah/workspace/telematics_tracker/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:80
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /home/sarah/workspace/telematics_tracker/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:116
 Symfony\Component\Console\Application->run() at /home/sarah/workspace/telematics_tracker/bin/console:27

Which is correct as such, since I have a column called 'fleetNo' but not one called 'fleet_no' in the 'fuelData' table. This was not one of the changes that I made either. I have searched the project directory for any other instance of 'fleet_no' but there aren't any.

Below is a copy of the fuelData entity.

<?php
// src/AppBundle/Entity/FuelData.php
namespace AppBundle\Entity;

use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\Column;

/**
 * @ORM\Entity
 * @ORM\Table(name="fuelData")
 * 
 *
 */

class FuelData
{

/**
 * @Assert\NotBlank()
 * @ORM\Column(type="string")
 * @ORM\Id
 */
public $fleetNo;

/**
 * @Assert\NotBlank()
 * @ORM\Column(type="string")
 */
public $startDate;

/**
 * @Assert\NotBlank()
 * @ORM\Column(type="string")
 */
public $endDate;

/**
 * Set fleetNo
 *
 * @param string $fleetNo
 *
 * @return FuelData
 */
public function setFleetNo($fleetNo)
{
    $this->fleetNo = $fleetNo;

    return $this;
}

/**
 * Get fleetNo
 *
 * @return string
 */
public function getFleetNo()
{
    return $this->fleetNo;
}

/**
 * Set startDate
 *
 * @param string $startDate
 *
 * @return FuelData
 */
public function setStartDate($startDate)
{
    $this->startDate = $startDate;

    return $this;
}

/**
 * Get startDate
 *
 * @return string
 */
public function getStartDate()
{
    return $this->startDate;
}

/**
 * Set endDate
 *
 * @param string $endDate
 *
 * @return FuelData
 */
public function setEndDate($endDate)
{
    $this->endDate = $endDate;

    return $this;
}

/**
 * Get endDate
 *
 * @return string
 */
public function getEndDate()
{
    return $this->endDate;
}
}

The only thing that I can think of is that the column name is being converted from camelCase to underscore by something.

Is there something that I have missed or should I be looking in a different place?

Below are the relevant parts of my config.yml:

doctrine:
    dbal:
        default_connection: maxdb
        connections:
            maxdb:
                driver:   pdo_mysql
                host:     "%database_host%"
                port:     "%database_port%"
                dbname:   "%database_name%"
                user:     "%database_user%"
                password: "%database_password%"
                charset:  UTF8
            foxdb:
                driver:   pdo_mysql
                host:     "%database_host2%"
                port:     "%database_port2%"
                dbname:   "%database_name2%"
                user:     "%database_user2%"
                password: "%database_password2%"
                charset:  UTF8
    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        default_entity_manager: maxem
        entity_managers:
            maxem:
                naming_strategy: doctrine.orm.naming_strategy.underscore
                connection: maxdb
                mappings:
                    AppBundle: ~
                    BWTCalendarBundle: ~
                    BWTFMBundle: ~
                    BWTHealthCheckBundle: ~
                    BWTSkytrackBundle: ~
                    BWTTelematicsBundle: ~
            foxem:
                naming_strategy: doctrine.orm.naming_strategy.underscore
                connection: foxdb
                mappings:
                    FoxBundle: ~
like image 654
Sarah Richardson Avatar asked Jan 24 '17 11:01

Sarah Richardson


1 Answers

orm:
    auto_generate_proxy_classes: "%kernel.debug%"
    default_entity_manager: maxem
    entity_managers:
        maxem:
            naming_strategy: doctrine.orm.naming_strategy.underscore

As you can see in your config you are using the UNDERSCORE naming strategy for the orm so that is what converts your field name.

You should do

app/console doctrine:schema:drop

to start off from clean then try changing the naming strategy.

In the end if you want to be sure to have the exact column name you want just add the name parameter to the colum annotation like so:

/**
* @Assert\NotBlank()
* @ORM\Column(type="string" name="fleetNo")
* @ORM\Id
*/
public $fleetNo;
like image 67
Mawcel Avatar answered Sep 21 '22 20:09

Mawcel