Doctrine 1
  1. Doctrine 1
  2. DC-368

createTablesFromModels() wants to create already existing FOREIGN KEY constraints

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.2.1
    • Fix Version/s: None
    • Component/s: Import/Export
    • Labels:
      None
    • Environment:
      mysql Ver 14.12 Distrib 5.0.75, for debian-linux-gnu (i486) using readline 5.2
      PHP 5.2.11-0.dotdeb.1 with Suhosin-Patch 0.9.7 (cli) (built: Sep 20 2009 09:41:43)
      Ubuntu 9.04

      Description

      If you create InnoDB tables from a given model directory, the table generator wants to create a foreign key constraint that already exists.

      1. Doctrine_Core::generateModelsFromYaml('yaml', 'models');
      2. Doctrine_Core::createTablesFromModels('models');
      3. Running this setup twice, will print out the following error:

      SQLSTATE[HY000]: General error: 1005 Can't create table './dev_mreiche/#sql-930_2cb7.frm' (errno: 121). Failing Query: "ALTER TABLE group_user ADD CONSTRAINT group_user_user_id_user_id FOREIGN KEY (user_id) REFERENCES user(id)". Failing Query: ALTER TABLE group_user ADD CONSTRAINT group_user_user_id_user_id FOREIGN KEY (user_id) REFERENCES user(id)

      1. schema.txt
        4 kB
        PpW8bNH3jy2A

        Activity

        Mike Reiche created issue -
        Mike Reiche made changes -
        Field Original Value New Value
        Description If you create InnoDB tables from a given model directory, the table generator wants to create a foreign key constraint that already exists.

        // tutorial.yml
        ---
        User:
          columns:
            id:
              type: integer(4)
              autoincrement: true
              primary: true
            username:
              type: string(255)
            password:
              type: string(255)
          attributes:
            export: all
            validate: true

        Group:
          tableName: group_table
          columns:
            id:
              type: integer(4)
              autoincrement: true
              primary: true
            name:
              type: string(255)
          relations:
            Users:
              foreignAlias: Groups
              class: User
              refClass: GroupUser

        GroupUser:
          columns:
            group_id:
              type: integer(4)
              primary: true
            user_id:
              type: integer(4)
              primary: true
          relations:
            Group:
              foreignAlias: GroupUsers
            User:
              foreignAlias: GroupUsers


        // setup.php
        try {
        Doctrine_Core::generateModelsFromYaml('yaml', 'models');
        Doctrine_Core::createTablesFromModels('models');
        } catch (Doctrine_Export_Exception $e) {
        echo $e->getMessage();
        }


        // Running this setup twice will print out the following error

        SQLSTATE[HY000]: General error: 1005 Can't create table './dev_mreiche/#sql-930_2cb7.frm' (errno: 121). Failing Query: "ALTER TABLE group_user ADD CONSTRAINT group_user_user_id_user_id FOREIGN KEY (user_id) REFERENCES user(id)". Failing Query: ALTER TABLE group_user ADD CONSTRAINT group_user_user_id_user_id FOREIGN KEY (user_id) REFERENCES user(id)
        If you create InnoDB tables from a given model directory, the table generator wants to create a foreign key constraint that already exists.

        1. Doctrine_Core::generateModelsFromYaml('yaml', 'models');
        2. Doctrine_Core::createTablesFromModels('models');
        3. Running this setup twice, will print out the following error:

        SQLSTATE[HY000]: General error: 1005 Can't create table './dev_mreiche/#sql-930_2cb7.frm' (errno: 121). Failing Query: "ALTER TABLE group_user ADD CONSTRAINT group_user_user_id_user_id FOREIGN KEY (user_id) REFERENCES user(id)". Failing Query: ALTER TABLE group_user ADD CONSTRAINT group_user_user_id_user_id FOREIGN KEY (user_id) REFERENCES user(id)
        Attachment testcase.zip [ 10239 ]
        PpW8bNH3jy2A made changes -
        Attachment schema.txt [ 10404 ]

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Mike Reiche
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: