Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 错误1215无法添加外键约束symfony_Php_Symfony - Fatal编程技术网

Php 错误1215无法添加外键约束symfony

Php 错误1215无法添加外键约束symfony,php,symfony,Php,Symfony,我与symfony在创建实体之间的关系时遇到问题。我希望在我的身体和我的身体之间建立一种多方面的关系。铭文与一所大学有关 班级题词: /** * Inscription * * @ORM\Table(name="Inscription") * @ORM\Entity(repositoryClass="IEPA\PlatformBundle\Repository\InscriptionRepository") */ class Inscription { /** * @ORM\Id * @

我与symfony在创建实体之间的关系时遇到问题。我希望在我的身体和我的身体之间建立一种多方面的关系。铭文与一所大学有关

班级题词:

/**
* Inscription
*
* @ORM\Table(name="Inscription")
*     @ORM\Entity(repositoryClass="IEPA\PlatformBundle\Repository\InscriptionRepository")
*/
class Inscription
{
/**
* @ORM\Id
* @ORM\Column(name="id", type="integer", nullable=true)
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var integer
* 
* @ORM\ManyToOne(targetEntity="IEPA\PlatformBundle\Entity\Universites")
* @ORM\JoinColumn(nullable=false)
*/
private $univInsc;
}
大学类别:

/**
* Universites
*
* @ORM\Table(name="universites")
* @ORM\Entity
* @ORM\Entity(repositoryClass="IEPA\PlatformBundle\Repository\UniversitesRepository")
*/
class Universites
{
/**
 * @var integer
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;
}
当我更新数据库(php应用程序/控制台条令:schema:update--force)时,我得到以下错误:

[Doctrine\DBAL\Exception\DriverException]
An exception occured while executing `ALTER TABLE inscription ADD CONTRAINT FK_D80C7901C5E240F6 FOREIGN KEY (univ_insc_id) REFERENCE universites (id):
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint


为此,必须在两个实体中声明关系。一个是一对一,另一个是一对一。并说明如何逆转数据:

    /**
    * Inscription
    *
    * @ORM\Table(name="Inscription")
    *     @ORM\Entity(repositoryClass="IEPA\PlatformBundle\Repository\InscriptionRepository")
    */
    class Inscription
    {
    /**
    * @ORM\Id
    * @ORM\Column(name="id", type="integer", nullable=true)
    * @ORM\GeneratedValue(strategy="AUTO")
    */
    private $id;
    /**
    * @var integer
    * 
    * @ORM\ManyToOne(targetEntity="IEPA\PlatformBundle\Entity\Universites", inversedBy="inscriptions")
    * @ORM\JoinColumn(name="idInscription", referencedColumnName="idInscription")
    */
    private $univInsc;
    }
在东京大学的一所大学里,关于奥拉·泰斯(Au niveau de ton université)的题词“我的朋友们:


在贵校,我们添加了一组题词:

    /**
    * Universites
    *
    * @ORM\Table(name="universites")
    * @ORM\Entity
    * @ORM\Entity(repositoryClass="IEPA\PlatformBundle\Repository\UniversitesRepository")
    */
    class Universites
    {
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

/**
 * @var Collection
 *
 * @ORM\OneToMany(targetEntity="IEPA\PlatformBundle\Entity\Inscription", mappedBy="univInsc")
 */
    private $inscriptions;
    }

还有一点:命名约定是用一个单数词来命名实体。您可以使用复数形式,但我建议您不要在同一项目中同时使用复数形式。

验证您是否已经在铭文实体中插入了行。如果是,请删除他,或者因为您的站点已联机而无法删除他

更改此行,如下所示:

@ORM\JoinColumn(nullable=false)
@ORM\ManyToOne(targetEntity="IEPA\PlatformBundle\Entity\Universites", inversedBy="inscriptions")

并将inversedBy=“铭文”添加到$univInsc,如下所示:

@ORM\JoinColumn(nullable=false)
@ORM\ManyToOne(targetEntity="IEPA\PlatformBundle\Entity\Universites", inversedBy="inscriptions")

并尝试执行条令:再次更新。

您收到此错误,因为
外键约束已存在


尝试直接删除事物拥有方(多对一)的
外键约束。删除后,重新运行命令来执行SQL更改。在ZF2中,这是
php index.php orm:schema工具:update--force
命令,它将重新创建索引。

在为其他项目转储一些表之后,我遇到了这个问题,问题是排序规则。utf8mb4_unicode_ci中的旧表和utf8mb4_unicode_ci中的新表,所以我在doctrine.yaml中对其进行了更改

发件人:

致:

而且。。。正在更新数据库架构

 5 queries were executed

[确定]数据库架构已成功更新

请原谅,谢谢你。在这一部分(我的朋友们),我的朋友们在双向关系的地方聚会。这是一个很好的例子。阿普雷斯斯塔吉斯。这是一个错误,因为这是一个秩序问题,需要执行《柳叶刀》的教义。Essaye de faire un
php应用程序/控制台原则:模式:更新——转储sql
et d'executer-cette-requette-directment dans mysql.d'accord je comprend mieux ta solution du bidirectionnnel:)。如果你在工作中遇到了变化,你会发现你是一个有创意的人。Bon sinon je vois encore 2选择了范围内的医生:1:Le nullable=铭文上的真实表面。2:le I majuscule sur le@ORM\Table。这是一个很小的社区。我的朋友:(我的名字是正确的,海报是正确的。谢谢你的回答。我的题词实体中没有插入行,只有在大学里。用你的解决方案,我仍然有同样的问题。我真的不明白你的“题词”是什么参考。解决方案:j'ai désactivéla vérification de la clétrangère en tapant la requète(php应用程序/控制台原则:schema:update--dump sql)+设置外键检查=0,directment dans MySQL
 5 queries were executed