我的问题是:
要清楚 - 我知道为什么SQL本身会失败.这很容易.失败的沉默本质就是问题所在.
我在PHP文件中有一个学说迁移,如下所示:
[... boilerplate ...]
public function up(Schema $schema)
{
$this->addSql(<<<SQL
-- This runs fine
CREATE TABLE [[redacted - this part runs fine]];
-- This fails with a unique key constraint
INSERT INTO `users_orgs` (`org_id`, `user_id`, `active`)
SELECT `oid`, `uid`, 1 as `active` FROM `orgs`;
-- Never gets here
ALTER TABLE `orgs` CHANGE `uid` `primary_user_id` int(11) unsigned DEFAULT NULL;
SQL
);
}
[... boilerplate ...]
Run Code Online (Sandbox Code Playgroud)
第二个语句由于唯一的键约束而失败(例如"键'PRIMARY'的重复条目'6-3'" - 它是复合键)但是没有报告错误.我知道它失败了,因为很明显最终语句永远不会运行,如果我手动运行违规语句,它就会失败.当我跑:
./bin/console doctrine:migrations:migrate
Run Code Online (Sandbox Code Playgroud)
从我的Symfony应用程序中调用doctrine迁移代码,它报告: …