我对我的教义实体进行了一些更改,需要更新数据库并收到以下错误。
$ php bin/console doctrine:schema:update -vvv
[DoctrineDBALSchemaSchemaException (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
DoctrineDBALSchemaSchemaException::columnDoesNotExist() at /home/sarah/workspace/telematics_tracker/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Table.php:671
DoctrineDBALSchemaTable->getColumn() at /home/sarah/workspace/telematics_tracker/vendor/doctrine/dbal/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php:711
DoctrineDBALPlatformsMySqlPlatform->getPreAlterTableAlterPrimaryKeySQL() at /home/sarah/workspace/telematics_tracker/vendor/doctrine/dbal/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php:639
DoctrineDBALPlatformsMySqlPlatform->getPreAlterTableIndexForeignKeySQL() at /home/sarah/workspace/telematics_tracker/vendor/doctrine/dbal/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php:621
DoctrineDBALPlatformsMySqlPlatform->getAlterTableSQL() at /home/sarah/workspace/telematics_tracker/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/SchemaDiff.php:199
DoctrineDBALSchemaSchemaDiff->_toSql() at /home/sarah/workspace/telematics_tracker/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/SchemaDiff.php:126
DoctrineDBALSchemaSchemaDiff->toSaveSql() at /home/sarah/workspace/telematics_tracker/vendor/doctrine/orm/lib/Doctrine/ORM/Tools/SchemaTool.php:883
DoctrineORMToolsSchemaTool->getUpdateSchemaSql() at /home/sarah/workspace/telematics_tracker/vendor/doctrine/orm/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/UpdateCommand.php:115
DoctrineORMToolsConsoleCommandSchemaToolUpdateCommand->executeSchemaCommand() at /home/sarah/workspace/telematics_tracker/vendor/doctrine/orm/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/AbstractCommand.php:65
DoctrineORMToolsConsoleCommandSchemaToolAbstractCommand->execute() at /home/sarah/workspace/telematics_tracker/vendor/doctrine/doctrine-bundle/Command/Proxy/UpdateSchemaDoctrineCommand.php:50
DoctrineBundleDoctrineBundleCommandProxyUpdateSchemaDoctrineCommand->execute() at /home/sarah/workspace/telematics_tracker/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:261
SymfonyComponentConsoleCommandCommand->run() at /home/sarah/workspace/telematics_tracker/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:839
SymfonyComponentConsoleApplication->doRunCommand() at /home/sarah/workspace/telematics_tracker/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:185
SymfonyComponentConsoleApplication->doRun() at /home/sarah/workspace/telematics_tracker/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:80
SymfonyBundleFrameworkBundleConsoleApplication->doRun() at /home/sarah/workspace/telematics_tracker/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:116
SymfonyComponentConsoleApplication->run() at /home/sarah/workspace/telematics_tracker/bin/console:27
这是正确的,因为我有一个名为"fleetNo"的列,但在"fuelData"表中没有一个名为"fleet_no"的列。这也不是我所做的更改之一。我已经在项目目录中搜索了任何其他"fleet_no"实例,但没有。
下面是燃料数据实体的副本。
<?php
// src/AppBundle/Entity/FuelData.php
namespace AppBundleEntity;
use SymfonyComponentValidatorConstraints as Assert;
use DoctrineORMMapping as ORM;
use DoctrineORMMappingColumn;
/**
* @ORMEntity
* @ORMTable(name="fuelData")
*
*
*/
class FuelData
{
/**
* @AssertNotBlank()
* @ORMColumn(type="string")
* @ORMId
*/
public $fleetNo;
/**
* @AssertNotBlank()
* @ORMColumn(type="string")
*/
public $startDate;
/**
* @AssertNotBlank()
* @ORMColumn(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;
}
}
我唯一能想到的是列名正在从驼峰转换为下划线。
我错过了什么,还是应该换个地方看?
以下是我的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: ~
orm:
auto_generate_proxy_classes: "%kernel.debug%"
default_entity_manager: maxem
entity_managers:
maxem:
naming_strategy: doctrine.orm.naming_strategy.underscore
正如您在配置中看到的那样,您正在为 orm 使用 UNDERSCORE 命名策略,以便转换您的字段名称。
你应该做
app/console doctrine:schema:drop
要从头开始,请尝试更改命名策略。
最后,如果您想确保拥有您想要的确切列名,只需将 name 参数添加到列式注释中,如下所示:
/**
* @AssertNotBlank()
* @ORMColumn(type="string" name="fleetNo")
* @ORMId
*/
public $fleetNo;