DDC-2551: schema-tool does not match join columns with identifier options #3203

Closed
opened 2026-01-22 14:15:19 +01:00 by admin · 11 comments
Owner

Originally created by @doctrinebot on GitHub (Jul 13, 2013).

Originally assigned to: @Ocramius on GitHub.

Jira issue originally created by user atans:

/****
 * Role
 *
 * @ORM\Entity
 * @ORM\Table(name="rbac*role", options={"collate"="utf8_general*ci"})
 * @package User\Entity
 */
class Role
{
    /****
     * @ORM\Id
     * @ORm\Column(name="role_id", type="integer", options={"unsigned"=true})
     * @ORM\GeneratedValue(strategy="AUTO")
     * @var int
     */
    protected $id;

    /****
     * @ORM\Column(name="role_name", name="string", length=32, nullable=true)
     * @var string
     */
    protected $name = null;


    /****
     * @ORM\ManyToOne(targetEntity="Role")
     * @ORM\JoinColumn(name="parent*role*id", referencedColumnName="id", nullable=true)
     * @var Role
     */
    protected $parentRole = null;
$ php vendor/doctrine/orm/bin/doctrine.php orm:schema-tool:update --force

Updating database schema...



  [Doctrine\DBAL\DBALException]
  An exception occurred while executing 'ALTER TABLE rbac_role ADD CONSTRAINT
   FK*C55D6FF2A44B56EA FOREIGN KEY (parent_role_id) REFERENCES rbac*role (id)
  ':

  SQLSTATE[HY000]: General error: 1005 Can't create table 'rbac.#sql-98_24b'
  (errno: 150)






  [PDOException]
  SQLSTATE[HY000]: General error: 1005 Can't create table 'rbac.#sql-98_24b'
  (errno: 150)

Problem here: ====================================================

ALTER TABLE rbac_role ADD CONSTRAINT
   FK*C55D6FF2A44B56EA FOREIGN KEY (parent_role_id) REFERENCES rbac*role (id)

 ==> `rbac*role (id)` should be `rbac_role (role*id)
Originally created by @doctrinebot on GitHub (Jul 13, 2013). Originally assigned to: @Ocramius on GitHub. Jira issue originally created by user atans: ``` /**** * Role * * @ORM\Entity * @ORM\Table(name="rbac*role", options={"collate"="utf8_general*ci"}) * @package User\Entity */ class Role { /**** * @ORM\Id * @ORm\Column(name="role_id", type="integer", options={"unsigned"=true}) * @ORM\GeneratedValue(strategy="AUTO") * @var int */ protected $id; /**** * @ORM\Column(name="role_name", name="string", length=32, nullable=true) * @var string */ protected $name = null; /**** * @ORM\ManyToOne(targetEntity="Role") * @ORM\JoinColumn(name="parent*role*id", referencedColumnName="id", nullable=true) * @var Role */ protected $parentRole = null; ``` ``` $ php vendor/doctrine/orm/bin/doctrine.php orm:schema-tool:update --force Updating database schema... [Doctrine\DBAL\DBALException] An exception occurred while executing 'ALTER TABLE rbac_role ADD CONSTRAINT FK*C55D6FF2A44B56EA FOREIGN KEY (parent_role_id) REFERENCES rbac*role (id) ': SQLSTATE[HY000]: General error: 1005 Can't create table 'rbac.#sql-98_24b' (errno: 150) [PDOException] SQLSTATE[HY000]: General error: 1005 Can't create table 'rbac.#sql-98_24b' (errno: 150) ``` Problem here: ==================================================== ``` ALTER TABLE rbac_role ADD CONSTRAINT FK*C55D6FF2A44B56EA FOREIGN KEY (parent_role_id) REFERENCES rbac*role (id) ==> `rbac*role (id)` should be `rbac_role (role*id) ```
admin added the Bug label 2026-01-22 14:15:19 +01:00
admin closed this issue 2026-01-22 14:15:20 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jul 15, 2013):

Comment created by @ocramius:

You can make your join column unsigned by using the columnDefinition property.

@doctrinebot commented on GitHub (Jul 15, 2013): Comment created by @ocramius: You can make your join column unsigned by using the `columnDefinition` property.
Author
Owner

@doctrinebot commented on GitHub (Jul 15, 2013):

Comment created by @ocramius:

The schema tool can't use the column options to match join columns with identifier columns.

Column options are one step further and cannot really be applied transitively to join columns, since they may contain vendor specific settings.

@doctrinebot commented on GitHub (Jul 15, 2013): Comment created by @ocramius: The schema tool can't use the column options to match join columns with identifier columns. Column options are one step further and cannot really be applied transitively to join columns, since they may contain vendor specific settings.
Author
Owner

@doctrinebot commented on GitHub (Jul 15, 2013):

Issue was closed with resolution "Can't Fix"

@doctrinebot commented on GitHub (Jul 15, 2013): Issue was closed with resolution "Can't Fix"
Author
Owner

@doctrinebot commented on GitHub (Jul 15, 2013):

Comment created by atans:

Thanks.


@ORM\JoinColumn(
 name="parent*role*id",
  referencedColumnName="id",
  nullable=true,
  columnDefinition="ALTER TABLE rbac*role ADD CONSTRAINT FK_C55D6FF2A44B56EA FOREIGN KEY (parent_role_id) REFERENCES rbac_role (role*id)"
)

Is this right ?

@doctrinebot commented on GitHub (Jul 15, 2013): Comment created by atans: Thanks. ``` @ORM\JoinColumn( name="parent*role*id", referencedColumnName="id", nullable=true, columnDefinition="ALTER TABLE rbac*role ADD CONSTRAINT FK_C55D6FF2A44B56EA FOREIGN KEY (parent_role_id) REFERENCES rbac_role (role*id)" ) ``` Is this right ?
Author
Owner

@doctrinebot commented on GitHub (Jul 15, 2013):

Comment created by @ocramius:

No. Your problem is that the join coulm is signed, whereas the referenced identifier column is unsigned.

@doctrinebot commented on GitHub (Jul 15, 2013): Comment created by @ocramius: No. Your problem is that the join coulm is signed, whereas the referenced identifier column is unsigned.
Author
Owner

@doctrinebot commented on GitHub (Jul 15, 2013):

Comment created by atans:

I do not understand, how can I do ?

@doctrinebot commented on GitHub (Jul 15, 2013): Comment created by atans: I do not understand, how can I do ?
Author
Owner

@doctrinebot commented on GitHub (Jul 15, 2013):

Comment created by @ocramius:

Simple solution: just drop the options={"unsigned"=true} from your annotations

@doctrinebot commented on GitHub (Jul 15, 2013): Comment created by @ocramius: Simple solution: just drop the `options={"unsigned"=true}` from your annotations
Author
Owner

@doctrinebot commented on GitHub (Jul 16, 2013):

Comment created by atans:

Thanks Marco Pivetta.

@doctrinebot commented on GitHub (Jul 16, 2013): Comment created by atans: Thanks Marco Pivetta.
Author
Owner

@doctrinebot commented on GitHub (Jul 16, 2013):

Comment created by atans:

Marco Pivetta, It is the same problem (2.4.0-RC2).

/****
 * Role
 *
 * @ORM\Entity
 * @ORM\Table(name="rbac*role", options={"collate"="utf8_general*ci"})
 * @package User\Entity
 */
class Role
{
    /****
     * @ORM\Id
     * @ORm\Column(name="role_id", type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     * @var int
     */
    protected $id;

    /****
     * @ORM\Column(name="role_name", name="string", length=32, nullable=true)
     * @var string
     */
    protected $name = null;


    /****
     * @ORM\ManyToOne(targetEntity="Role")
     * @ORM\JoinColumn(name="parent*role*id", referencedColumnName="id", nullable=true)
     * @var Role
     */
    protected $parentRole = null;

    /****
     * @ORM\ManyToMany(targetEntity="Permission")
     * @ORM\JoinTable(
     *  name="rbac*role*permission",
     *  joinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id")},
     *  inverseJoinColumns={@ORM\JoinColumn(name="perm_id", referencedColumnName="id")}
     * )
     * @var Permission[]
     */
    protected $permissions;
$ php vendor/doctrine/orm/bin/doctrine.php orm:schema-tool:update --dump-sql
ALTER TABLE rbac*role ADD CONSTRAINT FK*C55D6FF2A44B56EA FOREIGN KEY (parent
e*id) REFERENCES rbac*role (id);
ALTER TABLE rbac*role_permission CHANGE role_id role*id INT NOT NULL;
ALTER TABLE rbac*role_permission ADD CONSTRAINT FK*C31A0CF0D60322AC FOREIGN
(role*id) REFERENCES rbac*role (id);
ALTER TABLE rbac*role_permission ADD CONSTRAINT FK*C31A0CF0FA6311EF FOREIGN
(perm*id) REFERENCES rbac*permission (id);

rbac_role (id) does not change to rbac_role (role_id)

@doctrinebot commented on GitHub (Jul 16, 2013): Comment created by atans: Marco Pivetta, It is the same problem (2.4.0-RC2). ``` /**** * Role * * @ORM\Entity * @ORM\Table(name="rbac*role", options={"collate"="utf8_general*ci"}) * @package User\Entity */ class Role { /**** * @ORM\Id * @ORm\Column(name="role_id", type="integer") * @ORM\GeneratedValue(strategy="AUTO") * @var int */ protected $id; /**** * @ORM\Column(name="role_name", name="string", length=32, nullable=true) * @var string */ protected $name = null; /**** * @ORM\ManyToOne(targetEntity="Role") * @ORM\JoinColumn(name="parent*role*id", referencedColumnName="id", nullable=true) * @var Role */ protected $parentRole = null; /**** * @ORM\ManyToMany(targetEntity="Permission") * @ORM\JoinTable( * name="rbac*role*permission", * joinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id")}, * inverseJoinColumns={@ORM\JoinColumn(name="perm_id", referencedColumnName="id")} * ) * @var Permission[] */ protected $permissions; ``` ``` $ php vendor/doctrine/orm/bin/doctrine.php orm:schema-tool:update --dump-sql ALTER TABLE rbac*role ADD CONSTRAINT FK*C55D6FF2A44B56EA FOREIGN KEY (parent e*id) REFERENCES rbac*role (id); ALTER TABLE rbac*role_permission CHANGE role_id role*id INT NOT NULL; ALTER TABLE rbac*role_permission ADD CONSTRAINT FK*C31A0CF0D60322AC FOREIGN (role*id) REFERENCES rbac*role (id); ALTER TABLE rbac*role_permission ADD CONSTRAINT FK*C31A0CF0FA6311EF FOREIGN (perm*id) REFERENCES rbac*permission (id); ``` rbac_role (id) does not change to rbac_role (role_id)
Author
Owner

@doctrinebot commented on GitHub (Jul 16, 2013):

Comment created by @ocramius:

That's normal. I already marked the issue as "won't fix". Please don't use the issue tracker as a helpdesk.

@doctrinebot commented on GitHub (Jul 16, 2013): Comment created by @ocramius: That's normal. I already marked the issue as "won't fix". Please don't use the issue tracker as a helpdesk.
Author
Owner

@doctrinebot commented on GitHub (Jul 16, 2013):

Comment created by atans:

Oh, sorry

@doctrinebot commented on GitHub (Jul 16, 2013): Comment created by atans: Oh, sorry
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#3203