将数据添加到myadminPhp

时间:2019-03-03 18:50:24

标签: mysql

大家好,我试图将某些数据添加到表中,由于某种原因,检查表不允许向自身添加数据。我将其上传为SQL文件,因为我使用了模仿来模拟数据!

 /*
-- Use test;
-- Use mysql;
-- Use information_schema;
-- source f:/createempdepttable.sql;
-- Notice the forward slash  / in above statement
*/
-- section 13.1.28. MySQL Documentation DROP TABLE Syntax
Drop database if exists g00337857abu;
create database g00337857abu CHARACTER SET utf8 COLLATE UTF8_GENERAL_CI ;
Use g00337857abu;
Show tables;


DROP TABLE IF EXISTS invoice;

CREATE TABLE  invoice  (
   invoice_no  int(10) NOT NULL AUTO_INCREMENT,
   date  date NOT NULL,
   PRIMARY KEY(invoice_no)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


DROP TABLE IF EXISTS chauffeurs;

CREATE TABLE  chauffeurs  (
   chauffeur_id  int(10)  NOT NULL,
   fname  varchar(20) NOT NULL,
   lname  varchar(20) NOT NULL,
   phone  int(15) NOT NULL,
   address  varchar(20) NOT NULL,
   city  varchar(15) NOT NULL,
   county  varchar(15) NOT NULL,
   PRIMARY KEY (chauffeur_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS customers;

CREATE TABLE  customers  (
   customer_id  int(50)  NOT NULL AUTO_INCREMENT,
   fname  varchar(20) NOT NULL,
   lname  varchar(20) 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,
   status  ENUM('Approved','Unapproved'),
   driver_no varchar(20),
   PRIMARY KEY (customer_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


DROP TABLE IF EXISTS mechanics;

CREATE TABLE  mechanics  (
   mechanic_id  int(10)  NOT NULL AUTO_INCREMENT,
   fname  varchar(20) NOT NULL,
   lname  varchar(20) NOT NULL,
   PRIMARY KEY (mechanic_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


DROP TABLE IF EXISTS vehicles;

CREATE TABLE  vehicles (
   vehicle_id  int(10) NOT NULL AUTO_INCREMENT,
   category ENUM('Sedan','Hatchback','SUV', 'Coupe', 'Crossover') NOT NULL,
   no_of_seats  int(11) NOT NULL,
   brand  varchar(25) NOT NULL,
   model  varchar(25) NOT NULL,
   product_year  int(11) NOT NULL,
   rate_per_day  int(11) NOT NULL,
   PRIMARY KEY (vehicle_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS inspections;

CREATE TABLE  inspections  (
   inspection_id  int(10)  NOT NULL AUTO_INCREMENT,
   inspection_date  date NOT NULL,
   vehicle_id  int(10) NOT NULL,
   problem  varchar(50) NOT NULL,
   repair  varchar(55) NOT NULL,
   repair_complete  ENUM('Yes','No') NOT NULL,
   mechanic_id  int(10)  NOT NULL,
   PRIMARY KEY(inspection_id),
   KEY mechanic_idfk1 (mechanic_id),
   KEY vehicle_idfk2 (vehicle_id),
   CONSTRAINT vehicle_idfk2 FOREIGN KEY (vehicle_id) REFERENCES vehicles (vehicle_id),
   CONSTRAINT mechanic_idfk1 FOREIGN KEY (mechanic_id) REFERENCES mechanics (mechanic_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS payment_details;

CREATE TABLE  payment_details  (
   card_no  int(50) NOT NULL AUTO_INCREMENT,
   customer_id  int(50)  NOT NULL,
   CVV  int(11) NOT NULL,
   card_type  ENUM('Visa', 'Amex', 'Cash', 'Mastecard') NOT NULL,
   expiry_date  date NOT NULL,
   PRIMARY KEY(card_no),
   KEY customer_idfk1 (customer_id),
   CONSTRAINT customer_idfk1 FOREIGN KEY (customer_id) REFERENCES customers (customer_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS vehicle_collections;

CREATE TABLE  vehicle_collections  (
   collection_id  int(10) NOT NULL AUTO_INCREMENT,
   vehicle_id  int(10)  NOT NULL,
   collection_date  date NOT NULL,
   return_date  date NOT NULL,
   mileage_before  int(10) NOT NULL,
   mileage_after  int(10) NOT NULL,
   duration  int(5) NOT NULL,
   PRIMARY KEY (collection_id),
   KEY vehicle_idfk1 (vehicle_id),
   CONSTRAINT vehicle_idfk1 FOREIGN KEY (vehicle_id) REFERENCES vehicles (vehicle_id)
   ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS bookings;

   CREATE TABLE  bookings  (
   booking_id  int(50)  NOT NULL AUTO_INCREMENT,
   booking_date  date NOT NULL,
   start_date  date NOT NULL,
   end_date  date NOT NULL,
   invoice_no int(10)  NOT NULL,
   chauffeur_id int(10)NOT NULL,
   vehicle_id int(10)  NOT NULL,
   customer_id int(50) NOT NULL,
   chauffeur_req ENUM('Yes','No') NOT NULL,
   PRIMARY KEY (booking_id),
   KEY invoice_nofk2 (invoice_no),
   KEY chauffeur_idfk1 (chauffeur_id),
   KEY customer_idfk2 (customer_id),
   KEY vehicle_idfk2 (vehicle_id),
   CONSTRAINT invoice_nofk1 FOREIGN KEY (invoice_no) REFERENCES invoice (invoice_no) ON DELETE CASCADE,
   CONSTRAINT chauffeur_idfk2 FOREIGN KEY (chauffeur_id) REFERENCES chauffeurs (chauffeur_id)ON DELETE CASCADE,
   CONSTRAINT customer_idfk3 FOREIGN KEY (customer_id) REFERENCES customers (customer_id) ON DELETE CASCADE,
   CONSTRAINT vehicle_idfk3 FOREIGN KEY (vehicle_id) REFERENCES vehicles (vehicle_id)ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

php中的错误如下:

  

1452-无法添加或更新子行:外键约束失败(g00337857abuinspections,CONSTRAINT mechanic_idfk1外键(mechanic_id)参考{{1 }}(mechanics

可能是因为尚未填写机械表吗?到目前为止,我只填写了专职司机的顾客,他们很好

0 个答案:

没有答案