MySql Foreign key not working with tables containing dot (.)

2 posts, 0 answers
  1. Erik
    Erik avatar
    314 posts
    Member since:
    Feb 2008

    Posted 11 Mar 2011 Link to this post

    Hello,

    I have 2 tables, test 1 and test2 in MySql.
    Table test2 has a field LinkedTest1 that points to table test1, with a foreign key

    When i try this, no problem in ORM.

    Now, let's change test1 to testers.test1... oops... no foreign keys are created...

    What to do now...

    CREATE TABLE `testers.test1` (
      `idtest1` int(11) NOT NULL AUTO_INCREMENT,
      `bla` varchar(45) DEFAULT NULL,
      PRIMARY KEY (`idtest1`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1$$

    CREATE TABLE `test2` (
      `idtest2` int(11) NOT NULL AUTO_INCREMENT,
      `Boe` varchar(45) DEFAULT NULL,
      `LinkedTest1` int(11) DEFAULT NULL,
      PRIMARY KEY (`idtest2`),
      KEY `fkLinkedTest1` (`LinkedTest1`),
      CONSTRAINT `fk_test2_LinkedTest1` FOREIGN KEY (`LinkedTest1`) REFERENCES `testers.test1` (`idtest1`) ON DELETE NO ACTION ON UPDATE NO ACTION
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1$$

  2. Ady
    Admin
    Ady avatar
    589 posts

    Posted 17 Mar 2011 Link to this post

    Hi Proovit,

     Is 'testers' the same database as the 'test2' table? OpenAccess does not support referencing a table from another database, for MySql. In case both the tables are in the same database, please specify the table name as follows - `testers`.`test1` instead of - `testers.test1`.

    Do get back in case you need further assisstance.

    Kind regards,
    Ady
    the Telerik team
  3. DevCraft banner
Back to Top