DDC-2632: Doctrine reverse engineer doesn't honor NOT NULL foreign keys #3302

Closed
opened 2026-01-22 14:17:43 +01:00 by admin · 1 comment
Owner

Originally created by @doctrinebot on GitHub (Aug 24, 2013).

Originally assigned to: @Ocramius on GitHub.

Jira issue originally created by user paoloavezzano:

In this table, the two foreign keys (which I had to downgrade from primary keys because of Doctrine and then added a separate PK named 'Id') called 'Oggetto' and 'Sistema' have been set as NOT NULL.

-- -----------------------------------------------------
-- Table `mydb`.`Composizione`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`Composizione` ;

CREATE  TABLE IF NOT EXISTS `mydb`.`Composizione` (
  `Id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
  `Oggetto` INT UNSIGNED NOT NULL ,
  `Sistema` INT NOT NULL ,
  INDEX `fk*Oggetto_has_Sistema_Sistema1*idx` (`Sistema` ASC) ,
  INDEX `fk*Oggetto_has_Sistema_Oggetto1*idx` (`Oggetto` ASC) ,
  PRIMARY KEY (`Id`) ,
  CONSTRAINT `fk*Oggetto_has_Sistema*Oggetto1`
    FOREIGN KEY (`Oggetto` )
    REFERENCES `mydb`.`Oggetto` (`Id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk*Oggetto_has_Sistema*Sistema1`
    FOREIGN KEY (`Sistema` )
    REFERENCES `mydb`.`Sistema` (`Id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

Converting into Yaml here it is what I get.

    type: entity
    table: Composizione
    fields:
        id:
            id: true
            type: integer
            unsigned: true
            nullable: false
            column: Id
            generator:
                strategy: IDENTITY
    manyToOne:
        oggetto:
            targetEntity: Oggetto
            cascade:      {  }
            mappedBy:     null
            inversedBy:   null
            joinColumns:
                Oggetto:
                    referencedColumnName: Id
            orphanRemoval: false
        sistema:
            targetEntity: Sistema
            cascade:      {  }
            mappedBy:     null
            inversedBy:   null
            joinColumns:
                Sistema:
                    referencedColumnName: Id
            orphanRemoval: false
    lifecycleCallbacks: {  }

Basically it lost in translation the NOT NULL part.
To make it work I had to manually add two "nullable: false" lines as I did below:

    type: entity
    table: Composizione
    fields:
        id:
            id: true
            type: integer
            unsigned: true
            nullable: false
            column: Id
            generator:
                strategy: IDENTITY
    manyToOne:
        oggetto:
            targetEntity: Oggetto
            cascade:      {  }
            mappedBy:     null
            inversedBy:   null
            joinColumns:
                Oggetto:
                    referencedColumnName: Id
                    nullable:     false
            orphanRemoval: false
        sistema:
            targetEntity: Sistema
            cascade:      {  }
            mappedBy:     null
            inversedBy:   null
            joinColumns:
                Sistema:
                    referencedColumnName: Id
                    nullable:     false
            orphanRemoval: false
    lifecycleCallbacks: {  }

Is it a bug or am I missing something?

Regards,
Paolo Avezzano

Originally created by @doctrinebot on GitHub (Aug 24, 2013). Originally assigned to: @Ocramius on GitHub. Jira issue originally created by user paoloavezzano: In this table, the two foreign keys (which I had to downgrade from primary keys because of Doctrine and then added a separate PK named 'Id') called 'Oggetto' and 'Sistema' have been set as NOT NULL. ``` sql -- ----------------------------------------------------- -- Table `mydb`.`Composizione` -- ----------------------------------------------------- DROP TABLE IF EXISTS `mydb`.`Composizione` ; CREATE TABLE IF NOT EXISTS `mydb`.`Composizione` ( `Id` INT UNSIGNED NOT NULL AUTO_INCREMENT , `Oggetto` INT UNSIGNED NOT NULL , `Sistema` INT NOT NULL , INDEX `fk*Oggetto_has_Sistema_Sistema1*idx` (`Sistema` ASC) , INDEX `fk*Oggetto_has_Sistema_Oggetto1*idx` (`Oggetto` ASC) , PRIMARY KEY (`Id`) , CONSTRAINT `fk*Oggetto_has_Sistema*Oggetto1` FOREIGN KEY (`Oggetto` ) REFERENCES `mydb`.`Oggetto` (`Id` ) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `fk*Oggetto_has_Sistema*Sistema1` FOREIGN KEY (`Sistema` ) REFERENCES `mydb`.`Sistema` (`Id` ) ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB; ``` Converting into Yaml here it is what I get. ``` none type: entity table: Composizione fields: id: id: true type: integer unsigned: true nullable: false column: Id generator: strategy: IDENTITY manyToOne: oggetto: targetEntity: Oggetto cascade: { } mappedBy: null inversedBy: null joinColumns: Oggetto: referencedColumnName: Id orphanRemoval: false sistema: targetEntity: Sistema cascade: { } mappedBy: null inversedBy: null joinColumns: Sistema: referencedColumnName: Id orphanRemoval: false lifecycleCallbacks: { } ``` Basically it lost in translation the NOT NULL part. To make it work I had to manually add two "nullable: false" lines as I did below: ``` none type: entity table: Composizione fields: id: id: true type: integer unsigned: true nullable: false column: Id generator: strategy: IDENTITY manyToOne: oggetto: targetEntity: Oggetto cascade: { } mappedBy: null inversedBy: null joinColumns: Oggetto: referencedColumnName: Id nullable: false orphanRemoval: false sistema: targetEntity: Sistema cascade: { } mappedBy: null inversedBy: null joinColumns: Sistema: referencedColumnName: Id nullable: false orphanRemoval: false lifecycleCallbacks: { } ``` Is it a bug or am I missing something? Regards, Paolo Avezzano
admin added the BugInvalid labels 2026-01-22 14:17:43 +01:00
admin closed this issue 2026-01-22 14:17:43 +01:00
Author
Owner

@Ocramius commented on GitHub (Aug 18, 2017):

Closing as invalid.

Specifically, this bit is not correct:

            mappedBy:     null
            inversedBy:   null
@Ocramius commented on GitHub (Aug 18, 2017): Closing as `invalid`. Specifically, this bit is not correct: ```yml mappedBy: null inversedBy: null ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#3302