Results 1 to 4 of 4
  1. #1
    Ant_Snell is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2021
    Location
    UK
    Posts
    118

    2+ one to many relationships to one table in MySQL

    I have a large Access DB with many tables & relationships. I have exported the tables to MySQL but it only exports the table structure & data (Not the relationships / restraints, so I now need to recreate all the relationships in MySQL using workbench. I can create the primary keys but when creating foreign keys I get a Duplicate key on write or update error if I am trying have more than one chiled table linked to a parent table no matter what I try.

    I have:

    Employees table (tbl_Emp_Details) with a primary Key (Emp_ID)

    There are many child tables that have a one to many relationship with this table, all linked by the Emp_ID
    e.g.
    Employee Expenses (tbl_Emp_Expences) with a primary Key (Emp_Expences_ID) & foreign Key (Emp_ID)
    or
    Employee Alerts (tbl_Emp_Alerts) with a primary Key (Emp_Alerts_ID) & foreign Key (Emp_ID)

    I can create the primary key on all tables. I can then create the a foreign key, linked by Emp_ID on one table (e.g. Emp_Expences_ID to Emp_ID of tbl_Emp_Details) but if I try to create a second one to many relationship from tbl_Emp_Details to tbl_Emp_Alerts using Emp_Alerts_ID to Emp_ID I get:
    “Duplicate key on write or update”

    Full error message:
    Operation failed: There was an error while applying the SQL script to the database.
    ERROR 1005: Can't create table `TCTSandpit`.`tbl_Emp_Expences` (errno: 121 "Duplicate key on write or update")
    SQL Statement:
    ALTER TABLE `TCTSandpit`.`tbl_Emp_Expences`
    ADD CONSTRAINT `Emp_ID`
    FOREIGN KEY (`Emp_ID`)
    REFERENCES `TCTSandpit`.`tbl_Emp_Details` (`Emp_ID`)
    ON DELETE CASCADE
    ON UPDATE CASCADE

    Code:

    ALTER TABLE `TCTSandpit`.`tbl_Emp_Expences`
    ADD CONSTRAINT `Emp_ID`
    FOREIGN KEY (`Emp_ID`)
    REFERENCES `TCTSandpit`.`tbl_Emp_Details` (`Emp_ID`)
    ON DELETE CASCADE
    ON UPDATE CASCADE;



    I have been working on this for days now and tried everything I can think of, if anyone can help I will be grateful

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    I don't have any experience with MySql workbench, but you might investigate this thread by cheekybuddha that deals with creating ddl from a (Access) database. It will identify all relationships and put them into a group that you may be able to use with MySQL workbench.

  3. #3
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Are you aware of MySql forums? It seems pretty comprehensive.
    MySQL :: MySQL Forums

  4. #4
    Ant_Snell is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2021
    Location
    UK
    Posts
    118
    Thanks Both Orange & Davegri, I was not aware of thees other forums, I will give them a go

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 16
    Last Post: 04-02-2020, 04:49 PM
  2. Help - linked MySQL table & VBA
    By Leopolleke in forum Programming
    Replies: 3
    Last Post: 05-15-2018, 04:55 PM
  3. MySQL slave table crashed, how to fix it?
    By volkerjung in forum Misc
    Replies: 1
    Last Post: 09-17-2015, 06:02 AM
  4. Inserting Data to Access Table (Local) from MySQL table (Net)
    By gambit1430 in forum Import/Export Data
    Replies: 2
    Last Post: 09-26-2014, 01:34 AM
  5. mySQL statement not updating table!!
    By Ran in forum SQL Server
    Replies: 3
    Last Post: 01-10-2012, 11:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums