referntial integrity issue with two tables cant delete a record





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















So I am trying to delete a record from customers table. I would assume it's a referential integrity issue, however I don't really see what is wrong with it. Could anyone shed some light? Please and Thanks. Error Message below



 DELETE FROM customers
WHERE customer_id = 1


table structures:



    CREATE TABLE  payment_details  (
paytype_id varchar(10),
card_no int(8) NOT NULL,
customer_id int(50) NOT NULL,
CVV int(3) NOT NULL,
card_type ENUM ('Visa', 'Amex', 'American Express', 'Mastercard') NOT NULL,
expiry_date DATE NOT NULL,
PRIMARY KEY(paytype_id),
KEY customer_idfk1 (customer_id),
CONSTRAINT customer_idfk1 FOREIGN KEY (customer_id) REFERENCES customers (customer_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


and



CREATE TABLE  customers  (
customer_id int(50) NOT NULL AUTO_INCREMENT,
fname varchar(20) NOT NULL,
lname varchar(20) NOT NULL,
dateOfBirth date NOT NULL,
address varchar(30) NOT NULL,
city varchar(20) NOT NULL,
county ENUM('Armagh','Carlow','Cavan','Clare','Cork','Derry','Donegal','Down','Dublin','Fermanagh','Galway','Kerry','Kildare','Kilkenny','Laois','Leitrim','Limerick','Longford','Louth','Mayo','Meath','Monaghan','Offaly','Roscommon','Sligo','Tipperary','Tyrone','Waterford','Westmeath','Wexford','Wicklow') NOT NULL,
phone int(10) NOT NULL,
email varchar(20) NOT NULL,
payment_method ENUM ('Visa', 'Amex', 'Cash', 'American Express', 'Mastercard') NOT NULL,
valid_licence varchar(5) NOT NULL,
status varchar(10),
PRIMARY KEY (customer_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;



error - #1451 - Cannot delete or update a parent row: a foreign key
constraint fails (g00337857abu.payment_details, CONSTRAINT
customer_idfk1 FOREIGN KEY (customer_id) REFERENCES customers
(customer_id))










share





























    0















    So I am trying to delete a record from customers table. I would assume it's a referential integrity issue, however I don't really see what is wrong with it. Could anyone shed some light? Please and Thanks. Error Message below



     DELETE FROM customers
    WHERE customer_id = 1


    table structures:



        CREATE TABLE  payment_details  (
    paytype_id varchar(10),
    card_no int(8) NOT NULL,
    customer_id int(50) NOT NULL,
    CVV int(3) NOT NULL,
    card_type ENUM ('Visa', 'Amex', 'American Express', 'Mastercard') NOT NULL,
    expiry_date DATE NOT NULL,
    PRIMARY KEY(paytype_id),
    KEY customer_idfk1 (customer_id),
    CONSTRAINT customer_idfk1 FOREIGN KEY (customer_id) REFERENCES customers (customer_id)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;


    and



    CREATE TABLE  customers  (
    customer_id int(50) NOT NULL AUTO_INCREMENT,
    fname varchar(20) NOT NULL,
    lname varchar(20) NOT NULL,
    dateOfBirth date NOT NULL,
    address varchar(30) NOT NULL,
    city varchar(20) NOT NULL,
    county ENUM('Armagh','Carlow','Cavan','Clare','Cork','Derry','Donegal','Down','Dublin','Fermanagh','Galway','Kerry','Kildare','Kilkenny','Laois','Leitrim','Limerick','Longford','Louth','Mayo','Meath','Monaghan','Offaly','Roscommon','Sligo','Tipperary','Tyrone','Waterford','Westmeath','Wexford','Wicklow') NOT NULL,
    phone int(10) NOT NULL,
    email varchar(20) NOT NULL,
    payment_method ENUM ('Visa', 'Amex', 'Cash', 'American Express', 'Mastercard') NOT NULL,
    valid_licence varchar(5) NOT NULL,
    status varchar(10),
    PRIMARY KEY (customer_id)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;



    error - #1451 - Cannot delete or update a parent row: a foreign key
    constraint fails (g00337857abu.payment_details, CONSTRAINT
    customer_idfk1 FOREIGN KEY (customer_id) REFERENCES customers
    (customer_id))










    share

























      0












      0








      0








      So I am trying to delete a record from customers table. I would assume it's a referential integrity issue, however I don't really see what is wrong with it. Could anyone shed some light? Please and Thanks. Error Message below



       DELETE FROM customers
      WHERE customer_id = 1


      table structures:



          CREATE TABLE  payment_details  (
      paytype_id varchar(10),
      card_no int(8) NOT NULL,
      customer_id int(50) NOT NULL,
      CVV int(3) NOT NULL,
      card_type ENUM ('Visa', 'Amex', 'American Express', 'Mastercard') NOT NULL,
      expiry_date DATE NOT NULL,
      PRIMARY KEY(paytype_id),
      KEY customer_idfk1 (customer_id),
      CONSTRAINT customer_idfk1 FOREIGN KEY (customer_id) REFERENCES customers (customer_id)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8;


      and



      CREATE TABLE  customers  (
      customer_id int(50) NOT NULL AUTO_INCREMENT,
      fname varchar(20) NOT NULL,
      lname varchar(20) NOT NULL,
      dateOfBirth date NOT NULL,
      address varchar(30) NOT NULL,
      city varchar(20) NOT NULL,
      county ENUM('Armagh','Carlow','Cavan','Clare','Cork','Derry','Donegal','Down','Dublin','Fermanagh','Galway','Kerry','Kildare','Kilkenny','Laois','Leitrim','Limerick','Longford','Louth','Mayo','Meath','Monaghan','Offaly','Roscommon','Sligo','Tipperary','Tyrone','Waterford','Westmeath','Wexford','Wicklow') NOT NULL,
      phone int(10) NOT NULL,
      email varchar(20) NOT NULL,
      payment_method ENUM ('Visa', 'Amex', 'Cash', 'American Express', 'Mastercard') NOT NULL,
      valid_licence varchar(5) NOT NULL,
      status varchar(10),
      PRIMARY KEY (customer_id)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8;



      error - #1451 - Cannot delete or update a parent row: a foreign key
      constraint fails (g00337857abu.payment_details, CONSTRAINT
      customer_idfk1 FOREIGN KEY (customer_id) REFERENCES customers
      (customer_id))










      share














      So I am trying to delete a record from customers table. I would assume it's a referential integrity issue, however I don't really see what is wrong with it. Could anyone shed some light? Please and Thanks. Error Message below



       DELETE FROM customers
      WHERE customer_id = 1


      table structures:



          CREATE TABLE  payment_details  (
      paytype_id varchar(10),
      card_no int(8) NOT NULL,
      customer_id int(50) NOT NULL,
      CVV int(3) NOT NULL,
      card_type ENUM ('Visa', 'Amex', 'American Express', 'Mastercard') NOT NULL,
      expiry_date DATE NOT NULL,
      PRIMARY KEY(paytype_id),
      KEY customer_idfk1 (customer_id),
      CONSTRAINT customer_idfk1 FOREIGN KEY (customer_id) REFERENCES customers (customer_id)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8;


      and



      CREATE TABLE  customers  (
      customer_id int(50) NOT NULL AUTO_INCREMENT,
      fname varchar(20) NOT NULL,
      lname varchar(20) NOT NULL,
      dateOfBirth date NOT NULL,
      address varchar(30) NOT NULL,
      city varchar(20) NOT NULL,
      county ENUM('Armagh','Carlow','Cavan','Clare','Cork','Derry','Donegal','Down','Dublin','Fermanagh','Galway','Kerry','Kildare','Kilkenny','Laois','Leitrim','Limerick','Longford','Louth','Mayo','Meath','Monaghan','Offaly','Roscommon','Sligo','Tipperary','Tyrone','Waterford','Westmeath','Wexford','Wicklow') NOT NULL,
      phone int(10) NOT NULL,
      email varchar(20) NOT NULL,
      payment_method ENUM ('Visa', 'Amex', 'Cash', 'American Express', 'Mastercard') NOT NULL,
      valid_licence varchar(5) NOT NULL,
      status varchar(10),
      PRIMARY KEY (customer_id)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8;



      error - #1451 - Cannot delete or update a parent row: a foreign key
      constraint fails (g00337857abu.payment_details, CONSTRAINT
      customer_idfk1 FOREIGN KEY (customer_id) REFERENCES customers
      (customer_id))








      mysql





      share












      share










      share



      share










      asked 8 mins ago









      GrubertusinoGrubertusino

      22




      22






















          0






          active

          oldest

          votes












          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "182"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f234149%2freferntial-integrity-issue-with-two-tables-cant-delete-a-record%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Database Administrators Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f234149%2freferntial-integrity-issue-with-two-tables-cant-delete-a-record%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          SQL Server 17 - Attemping to backup to remote NAS but Access is denied

          Always On Availability groups resolving state after failover - Remote harden of transaction...

          Restoring from pg_dump with foreign key constraints