DDC-1117: \Doctrine\ORM\Tools\SchemaTool::dropSchema drop table it should not #1400

Closed
opened 2026-01-22 13:13:11 +01:00 by admin · 3 comments
Owner

Originally created by @doctrinebot on GitHub (Apr 15, 2011).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user mathroc:

I got two entities class, user and authorization (see below) which tables were created using $tools->updateSchema(Array('CMS\User')) and then $tools->updateSchema(Array('CMS\User')) (CMS\User can be use without authorization)

when creating the table for CMS\Authorization, an intermediate table (cms_authorizations_roles) is create for the ManyToMany relation.

but, when I try to remove the CMS\Authorization table with $tools->dropSchema(Array('CMS\Authorization')) it try to remove the tables cms_authorization, cms_authorizations_roles and cms_user (but failed because of foreign key to cms_user)

the problem is not that it fails, it's that it shouldn't try to remove cms_user

namespace CMS;

/**** 
 * @Entity
 * @table(name="cms_user")
 */
class User extends \WM\Resource {
    protected 
        /*** @Id @Column(type="integer") @GeneratedValue ***/
        $id = null, 
        /*** @Column(type="string",unique=true) ***/
        $name = null, 
        /*** @Column ***/
        $password = null, 
        /****
        * @ManyToMany(targetEntity="CMS\Role", inversedBy="users",cascade={"persist"})
        * @JoinTable(name="cms*users*roles",
        *   joinColumns={@JoinColumn(name="cms_user", referencedColumnName="id")},
        *   inverseJoinColumns={@JoinColumn(name="cms_role", referencedColumnName="id")}
        * )
        */
        $roles = null;
}

/**** 
 * @Entity
 * @table(name="cms_authorization")
 */
class Authorization extends \WM\Resource {
    protected 
        /*** @Id @Column(type="integer") @GeneratedValue ***/
        $id = null, 
        /*** @Column(type="string",unique=true) ***/
        $resource_class = null, 
        /****
        * @ManyToMany(targetEntity="CMS\Role",inversedBy="users",cascade={"persist"})
        * @JoinTable(name="cms*authorizations*roles",
        *   joinColumns={@JoinColumn(name="cms_authorization", referencedColumnName="id")},
        *   inverseJoinColumns={@JoinColumn(name="cms_role", referencedColumnName="id")}
        * )
        */
        $roles = null;
}
Originally created by @doctrinebot on GitHub (Apr 15, 2011). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user mathroc: I got two entities class, user and authorization (see below) which tables were created using `$tools->updateSchema(Array('CMS\User'))` and then `$tools->updateSchema(Array('CMS\User'))` (CMS\User can be use without authorization) when creating the table for CMS\Authorization, an intermediate table (cms_authorizations_roles) is create for the ManyToMany relation. but, when I try to remove the CMS\Authorization table with `$tools->dropSchema(Array('CMS\Authorization'))` it try to remove the tables cms_authorization, cms_authorizations_roles and cms_user (but failed because of foreign key to cms_user) the problem is not that it fails, it's that it shouldn't try to remove cms_user ``` namespace CMS; /**** * @Entity * @table(name="cms_user") */ class User extends \WM\Resource { protected /*** @Id @Column(type="integer") @GeneratedValue ***/ $id = null, /*** @Column(type="string",unique=true) ***/ $name = null, /*** @Column ***/ $password = null, /**** * @ManyToMany(targetEntity="CMS\Role", inversedBy="users",cascade={"persist"}) * @JoinTable(name="cms*users*roles", * joinColumns={@JoinColumn(name="cms_user", referencedColumnName="id")}, * inverseJoinColumns={@JoinColumn(name="cms_role", referencedColumnName="id")} * ) */ $roles = null; } /**** * @Entity * @table(name="cms_authorization") */ class Authorization extends \WM\Resource { protected /*** @Id @Column(type="integer") @GeneratedValue ***/ $id = null, /*** @Column(type="string",unique=true) ***/ $resource_class = null, /**** * @ManyToMany(targetEntity="CMS\Role",inversedBy="users",cascade={"persist"}) * @JoinTable(name="cms*authorizations*roles", * joinColumns={@JoinColumn(name="cms_authorization", referencedColumnName="id")}, * inverseJoinColumns={@JoinColumn(name="cms_role", referencedColumnName="id")} * ) */ $roles = null; } ```
admin added the Bug label 2026-01-22 13:13:11 +01:00
admin closed this issue 2026-01-22 13:13:12 +01:00
Author
Owner

@doctrinebot commented on GitHub (May 1, 2011):

Comment created by @beberlei:

Can you try again? I changed alot of in the dropSchema method in master and 2.0.x branches.

@doctrinebot commented on GitHub (May 1, 2011): Comment created by @beberlei: Can you try again? I changed alot of in the dropSchema method in master and 2.0.x branches.
Author
Owner

@doctrinebot commented on GitHub (May 8, 2011):

Comment created by mathroc:

juste update to 2.0.x, it is working :) thank you!

@doctrinebot commented on GitHub (May 8, 2011): Comment created by mathroc: juste update to 2.0.x, it is working :) thank you!
Author
Owner

@doctrinebot commented on GitHub (May 8, 2011):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (May 8, 2011): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1400