Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8960277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:37:42+00:00 2026-06-15T15:37:42+00:00

When using Doctrine ORM in Symfony2, I have the following tables generated from three

  • 0

When using Doctrine ORM in Symfony2, I have the following tables generated from three different entities, of which accessory has two foreign key constraints (marked A and B below).

describe publication;
+-------------------+--------------+------+-----+---------+----------------+
| Field             | Type         | Null | Key | Default | Extra          |
+-------------------+--------------+------+-----+---------+----------------+
| id                | int(11)      | NO   | PRI | NULL    | auto_increment |
| kid               | varchar(10)  | NO   |     | NULL    |                |
| title             | varchar(255) | NO   |     | NULL    |                |
| title_canonical   | varchar(255) | NO   |     | NULL    |                | <- A
| created           | datetime     | NO   |     | NULL    |                |
| modified          | datetime     | NO   |     | NULL    |                |
+-------------------+--------------+------+-----+---------+----------------+

describe accessory;
+-------------------+--------------+------+-----+---------+----------------+
| Field             | Type         | Null | Key | Default | Extra          |
+-------------------+--------------+------+-----+---------+----------------+
| id                | int(11)      | NO   | PRI | NULL    | auto_increment |
| publication_title | varchar(255) | YES  |     | NULL    |                | <- A
| index_id          | int(11)      | NO   |     | NULL    |                |
| index_alias       | varchar(255) | NO   |     | NULL    |                |
| value             | longtext     | NO   |     | NULL    |                |
| attribute_name    | varchar(255) | YES  |     | NULL    |                | <- B
+-------------------+--------------+------+-----+---------+----------------+

describe attribute;
+-------------------+--------------+------+-----+---------+----------------+
| Field             | Type         | Null | Key | Default | Extra          |
+-------------------+--------------+------+-----+---------+----------------+
| id                | int(11)      | NO   | PRI | NULL    | auto_increment |
| name              | varchar(255) | NO   |     | NULL    |                |
| name_canonical    | varchar(255) | NO   |     | NULL    |                | <- B
| parameter         | varchar(16)  | NO   |     | NULL    |                |
+-------------------+--------------+------+-----+---------+----------------+

The foreign keys are mapped with annotations:

Publication.php

/**
 * @ORM\OneToMany(targetEntity="Accessory", mappedBy="publication")
 */
protected $accessories;

Accessory.php

/**
 * @ORM\ManyToOne(targetEntity="Publication", inversedBy="accessories")
 * @ORM\JoinColumn(name="publication_title", referencedColumnName="title_canonical")
 */
protected $publication;


/**
 * @ORM\ManyToOne(targetEntity="Attribute", inversedBy="accessories")
 * @ORM\JoinColumn(name="attribute_name", referencedColumnName="name_canonical")
 */
protected $attribute;

Attribute.php

/**
 * @ORM\OneToMany(targetEntity="Accessory", mappedBy="attribute")
 */
protected $accessories;

but upon running php app/console doctrine:schema:update --force I got this exception

[Doctrine\DBAL\DBALException]                                                                                                                                               
An exception occurred while executing 'ALTER TABLE accessory ADD CONSTRAINT FK_A1B1251CCEE83EE7 FOREIGN KEY (publication_title) REFERENCES publication (title_canonical)':  

SQLSTATE[HY000]: General error: 1005 Can't create table 'publicationsapp.#sql-2a3c_2828' (errno: 150)

So I ran php app/console doctrine:schema:update --dump-sql

ALTER TABLE accessory ADD CONSTRAINT FK_A1B1251CCEE83EE7 FOREIGN KEY (publication_title) REFERENCES publication (title_canonical);
ALTER TABLE accessory ADD CONSTRAINT FK_A1B1251C5CBDA8E FOREIGN KEY (attribute_name) REFERENCES attribute (name_canonical);
CREATE INDEX IDX_A1B1251CCEE83EE7 ON accessory (publication_title);
CREATE INDEX IDX_A1B1251C5CBDA8E ON accessory (attribute_name);

What’s the correct way to resolve this? Should I edit the tables manually or with Doctrine?

Based on what I’ve read about errno 150, the foreign column needs to be indexed, but can’t Doctrine handle this automatically?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:37:43+00:00Added an answer on June 15, 2026 at 3:37 pm

    One could add unique=true to both $nameCanonical and $titleCanonical properties or whichever columns are referenced by the foreign key. Then drop and run the schema update command to recreate the tables.

    In the case of $titleCanonical

    /**
     * @var string
     *
     * @ORM\Column(name="title_canonical", type="string", length=255, unique=true)
     */
    private $titleCanonical;
    

    But ideally with Doctrine, the foreign keys should be referenced to the other table’s primary key to make it valid.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a join-table which is created by using @ORM\ManyToMany annotation in Symfony2/Doctrine. It
I'm using Symfony2 with Doctrine. I have tons of entities (tables) and here's what
In my Symfony2 browsergame I have an user entity using the Doctrine 2 ORM.
I am getting following error message when using Doctrine ORM in Codeigniter. ( !
I am using Doctrine ORM for php and Zend MVC. I have a mysql
Entities in symfony 2 have doctrine tags that are preceded with @ORM\ (eg @ORM\Entity).
I use Doctrine 2 as ORM in Symfony framework. Using annotation-based mapping for entities,
Newest Version Symfony2 and using MAMP on a MAC. Following command: php app/console doctrine:mapping:convert
I have an entity Movie which has a unique constraint through doctrine annotation. Based
A quick question. I'm using symfony1.4 with Doctrine ORM and sfGuardDoctrinePlugin. I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.