Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2522

When changing a manyToMany relationship to a stand alone table with the same table name, doctrine fails to properly update schema.

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.2.3
    • Fix Version/s: None
    • Component/s: Tools
    • Security Level: All
    • Labels:
      None
    • Environment:
      Discovered while using doctrine orm in Symfony 2.1. MySQL

      Description

      To start with I created a manyToMany relationship in my user entity to my referrers entity. The association was named "referrals" and used a table named "user_referrals" as the manyToMany join table.

      I later removed the manyToMany join association in favor of a stand-alone entity. I created an entity named UserReferrals. I kept the table name "user_referrals".

      When doctrine attempts to update the mysql database schema, I receive this error...

      SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key

      This is the SQL attempting to be executed:
      ALTER TABLE user_referrals ADD id INT AUTO_INCREMENT NOT NULL, ADD created DATETIME NOT NULL, ADD updated DATETIME NOT NULL, ADD status VARCHAR(255) NOT NULL, CHANGE referrer_id referrer_id INT DEFAULT NULL, CHANGE user_id user_id INT DEFAULT NULL

      Is this a bug? Running the SQL directly in MYSQL also fails with the same error.

        Activity

        Jeremy Moore created issue -
        Hide
        Peter Rehm added a comment -

        In the SQL Statement there is the primary key definition missing. In your case the adjustment to

        ALTER TABLE user_referrals ADD id INT AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id), ADD created DATETIME NOT NULL, ADD updated DATETIME NOT NULL, ADD status VARCHAR(255) NOT NULL, CHANGE referrer_id referrer_id INT DEFAULT NULL, CHANGE user_id user_id INT DEFAULT NULL

        should make it.

        If have the same issue where the schema tool / migrations generated the following statements:

        ALTER TABLE ArticleToSet DROP PRIMARY KEY
        ALTER TABLE ArticleToSet ADD id INT AUTO_INCREMENT NOT NULL, CHANGE article_id article_id INT DEFAULT NULL, CHANGE articleSet_id articleSet_id INT DEFAULT NULL
        ALTER TABLE ArticleToSet ADD PRIMARY KEY (id)

        Updating it manually to the following fixes it:

        ALTER TABLE ArticleArticleToSet DROP PRIMARY KEY"
        ALTER TABLE ArticleArticleToSet ADD id INT AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id), CHANGE article_id article_id INT DEFAULT NULL, CHANGE articleSet_id articleSet_id INT DEFAULT NULL

        The situation appeared when I have changed from a composite key to a separate key.

        Show
        Peter Rehm added a comment - In the SQL Statement there is the primary key definition missing. In your case the adjustment to ALTER TABLE user_referrals ADD id INT AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id), ADD created DATETIME NOT NULL, ADD updated DATETIME NOT NULL, ADD status VARCHAR(255) NOT NULL, CHANGE referrer_id referrer_id INT DEFAULT NULL, CHANGE user_id user_id INT DEFAULT NULL should make it. If have the same issue where the schema tool / migrations generated the following statements: ALTER TABLE ArticleToSet DROP PRIMARY KEY ALTER TABLE ArticleToSet ADD id INT AUTO_INCREMENT NOT NULL, CHANGE article_id article_id INT DEFAULT NULL, CHANGE articleSet_id articleSet_id INT DEFAULT NULL ALTER TABLE ArticleToSet ADD PRIMARY KEY (id) Updating it manually to the following fixes it: ALTER TABLE ArticleArticleToSet DROP PRIMARY KEY" ALTER TABLE ArticleArticleToSet ADD id INT AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id), CHANGE article_id article_id INT DEFAULT NULL, CHANGE articleSet_id articleSet_id INT DEFAULT NULL The situation appeared when I have changed from a composite key to a separate key.

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DDC-2522, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Jeremy Moore
          • Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: