尝试重新加载灯具时出现问题 [英] Issue when trying to reload the fixtures

查看:40
本文介绍了尝试重新加载灯具时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用

php 应用程序/控制台原则:夹具:加载

php app/console doctrine:fixtures:load

我收到此错误:

SQLSTATE[23000]:违反完整性约束:1451 无法删除或更新父行:外键约束失败 (foo_db.Book, CONSTRAINT FK_C29271DD816C6140 FOREIGN KEY (author_id)参考文献作者 (id))

SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (foo_db.Book, CONSTRAINT FK_C29271DD816C6140 FOREIGN KEY (author_id) REFERENCES Author (id))

显示状态">purging database"时显示错误.

这是我的代码:

class Book{
...

/**
 * @ORM\ManyToOne(targetEntity="Author", inversedBy="books")
 */
private $author;

... 
}

class Author{
    ...
    /**
     * @ORM\OneToMany(targetEntity="Book", mappedBy="author")
     */
    private $books;

}

更多:我的老板有相同的代码,但没有那个错误.

More: my boss has the same code and it doesn't have that error.

有什么想法吗?

sf 2.0.1(刚刚更新)/ubuntu 10.10.

sf 2.0.1 (just updated)/ubuntu 10.10.

推荐答案

如果我猜对了,您使用的是 MySQL 数据库.如果是,那么您正面临 Doctrine2 的 doctrine-fixtures 库的当前版本的错误/问题.问题是他们使用 TRUNCATE 命令来清除当前的数据库值,但是这个命令在删除 MySQL 中的外部关联时有问题.

If I'm guessing correctly, you are using a MySQL database. If yes, then you are facing a bug/problem with the current version of the doctrine-fixtures library for Doctrine2. The problem is that they are using the TRUNCATE command to purge the current database values but this command has problem deleting foreign associations in MySQL.

参见这个问题这个 库的 GitHub 存储库上的更多信息和解决方法.

See this issue and this one on the GitHub repository of the library for more information and workarounds.

在我的特殊情况下,我从脚本运行此命令,因此为了使命令正常工作,我这样做:

In my particular case, I run this command from a script, so to make the command work correctly, I do:

php app/console doctrine:database:drop --force
php app/console doctrine:database:create

php app/console doctrine:schema:update --force

php app/console doctrine:fixtures:load --append

通过这种方式,清除是由 drop 命令完成的,附加与不附加的效果相同,因为在加载装置时数据库是空的.

This way, the purging is done by the drop command and appending has the same effect as not appending since the database is empty when the fixtures are loaded.

我必须承认我不知道为什么你的老板没有这个问题,也许他的数据库中没有与作者相关的书.

I must admit I don't know why your boss doesn't have the problem, maybe there is no book associated with an author in his database.

希望对您有所帮助.

问候,
马特

这篇关于尝试重新加载灯具时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆