我从Symfony2和Doctrine开始。在设置symfony并创建我的新包之后,我坚持反转我的postgre数据库。它在第一个表中返回一个异常:
[Doctrine\ORM\MappingMappingException]
Table tb_core_table has no primary key. Doctrine does not support reverse engineering from tables that don't have a primary key.
这是我在命令行执行的命令:
php app/console doctrine:mapping:convert yml ./src/ak/ProcessamentoBundle/Resources/config/doctrine --from-database --force
好的,到现在为止我已经知道所有的表都必须有pk,所以doctrine可以使用它们,这就是问题所在。我的“tb_core_table”是主键,但无论出于何种原因,学说都会忽略它。
我错过了一些配置?为什么它可以找到主键?
这是我的表DDL:
CREATE TABLE tb_core_table (
id_table integer NOT NULL,
id_aux_table integer NOT NULL,
no_table character varying(255),
st_table integer
);
CREATE SEQUENCE tb_core_table_id_table_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE ONLY tb_core_table
ADD CONSTRAINT tb_core_table_pkey PRIMARY KEY (id_table);
答案 0 :(得分:-1)
从代码库中搜索DatabaseDriver.php文件:
转到DatabaseDriver.php
在给定文件中搜索reverseEngineerMappingFromDatabase方法。
取消注释以下部分
//if ( ! $table->hasPrimaryKey()) {
// throw new MappingException(
// "Table " . $table->getName() . " has no primary key. Doctrine does not ".
// "support reverse engineering from tables that don't have a primary key."
//);
//}
//$pkColumns = $table->getPrimaryKey()->getColumns();
添加以下行
$pkColumns = array();
然后搜索方法getTablePrimaryKeys并注释其中的所有内容并返回空数组。
以上方法将删除没有主键的。 Doctrine不支持对没有主键的表进行逆向工程。使用实体生成工具时出错。