Skip to content

Loading…

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

Closed
doctrinebot opened this Issue · 11 comments

2 participants

@doctrinebot

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)
@doctrinebot

Comment created by @ocramius:

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

@doctrinebot

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

Issue was closed with resolution "Can't Fix"

@doctrinebot

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

Comment created by @ocramius:

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

@doctrinebot

Comment created by atans:

I do not understand, how can I do ?

@doctrinebot

Comment created by @ocramius:

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

@doctrinebot

Comment created by atans:

Thanks Marco Pivetta.

@doctrinebot

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);

rbacrole (id) does not change to rbac_role (roleid)

@doctrinebot

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

Comment created by atans:

Oh, sorry

@Ocramius Ocramius was assigned by doctrinebot
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.