在执行完Symfony2手册中解释的命令之后:
php app/console doctrine:mapping:import --force AcmeBlogBundle xml
php app/console doctrine:mapping:convert annotation ./src
php app/console doctrine:generate:entities AcmeBlogBundle它正确地创建了XML文件,正确地生成了实体。
但当我跑的时候
php app/console doctrine:schema:validate上面写着:
映射确定-映射文件是正确的。 数据库失败-数据库架构与当前映射文件不同步。
好的,我按照我运行的教程运行:
php app/console doctrine:schema:update --dump-sql在这里,我可以看到有很多ALTER命令。如下所示:
ALTER TABLE ea_restaurant_tag DROP FOREIGN KEY ea_restaurant_tag_ibfk_1;
ALTER TABLE ea_restaurant_tag DROP FOREIGN KEY ea_restaurant_tag_ibfk_2;
ALTER TABLE ea_restaurant_tag CHANGE id id INT AUTO_INCREMENT NOT NULL, CHANGE restaurant_id restaurant_id INT DEFAULT NULL, CHANGE login_id login_id INT DEFAULT NULL;
ALTER TABLE ea_restaurant_tag ADD CONSTRAINT FK_10C17C7E5CB2E05D FOREIGN KEY (login_id) REFERENCES ea_login (id);
ALTER TABLE ea_restaurant_tag ADD CONSTRAINT FK_10C17C7EB1E7706E FOREIGN KEY (restaurant_id) REFERENCES ea_restaurant (id);更新
这是restaurant_tag表的SQL "create“命令:
CREATE TABLE IF NOT EXISTS `ea_restaurant_tag` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`restaurant_id` int(10) unsigned NOT NULL,
`login_id` int(10) unsigned DEFAULT NULL,
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `login_id` (`login_id`),
KEY `restaurant_id` (`restaurant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
ALTER TABLE `ea_restaurant_tag`
ADD CONSTRAINT `ea_restaurant_tag_ibfk_1` FOREIGN KEY (`restaurant_id`) REFERENCES `ea_restaurant` (`id`) ON DELETE CASCADE,
ADD CONSTRAINT `ea_restaurant_tag_ibfk_2` FOREIGN KEY (`login_id`) REFERENCES `ea_login` (`id`) ON DELETE CASCADE;Doctribne生成的XML
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine- mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="AppBundle\Entity\EaRestaurantTag" table="ea_restaurant_tag">
<indexes>
<index name="login_id" columns="login_id"/>
<index name="restaurant_id" columns="restaurant_id"/>
</indexes>
<id name="id" type="integer" column="id">
<generator strategy="IDENTITY"/>
</id>
<field name="date" type="datetime" column="date" nullable="false">
<options>
<option name="default">CURRENT_TIMESTAMP</option>
</options>
</field>
<many-to-one field="login" target-entity="EaLogin" fetch="LAZY">
<join-columns>
<join-column name="login_id" referenced-column-name="id"/>
</join-columns>
</many-to-one>
<many-to-one field="restaurant" target-entity="EaRestaurant" fetch="LAZY">
<join-columns>
<join-column name="restaurant_id" referenced-column-name="id"/>
</join-columns>
</many-to-one>很奇怪,它试图删除当前的键,并重新创建其他的。为什么会发生这种事?
数据库是MySQL,所有表都是InnoDB。
发布于 2016-08-30 18:09:33
原则导入工具不支持未签名的主键。您可能需要通过在columnDefinition="INTEGER UNSIGNED"中设置JoinColumn或扩展EntityGenerator类来手动定义它。
https://stackoverflow.com/questions/33806423
复制相似问题