2015-10-19 5 views
0

Невозможно определить, что не так, когда генерируется исходная таблица. Проблема с ins_id вызывает проблему. Это Auto Increment, поэтому я оставил его нулевым, а все остальное - в таблице заведений, как в исходной таблице. Вот код.Ошибка SQL Workbench Ошибка 1452-исходная таблица не может быть создана

-- MySQL Workbench Forward Engineering 

SET @[email protected]@UNIQUE_CHECKS, UNIQUE_CHECKS=0; 
SET @[email protected]@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; 
SET @[email protected]@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES'; 

-- ----------------------------------------------------- 
-- Schema tks15 
-- ----------------------------------------------------- 
-- 
-- 
DROP SCHEMA IF EXISTS `tks15` ; 

-- ----------------------------------------------------- 
-- Schema tks15 
-- 
-- 
-- 
-- ----------------------------------------------------- 
CREATE SCHEMA IF NOT EXISTS `tks15` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ; 
USE `tks15` ; 

-- ----------------------------------------------------- 
-- Table `tks15`.`category` 
-- ----------------------------------------------------- 
DROP TABLE IF EXISTS `tks15`.`category` ; 

CREATE TABLE IF NOT EXISTS `tks15`.`category` (
    `cat_id` MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '', 
    `cat_type` ENUM('salary', 'bonus', 'pension', 'social security', 'unemployment', 'disability', 'royalty', 'interest', 'dividend', 'tax return', 'gift', 'child support', 'alimony', 'award', 'grant', 'scholarship', 'inheritance', 'housing', 'food', 'transportation', 'charity', 'investment', 'insurance', 'clothing', 'saving', 'health', 'personal', 'recreation', 'debt', 'school', 'childcare', 'misc') NOT NULL COMMENT '', 
    `cat_notes` VARCHAR(255) NULL COMMENT '', 
    PRIMARY KEY (`cat_id`) COMMENT '') 
ENGINE = InnoDB; 


-- ----------------------------------------------------- 
-- Table `tks15`.`institution` 
-- ----------------------------------------------------- 
DROP TABLE IF EXISTS `tks15`.`institution` ; 

CREATE TABLE IF NOT EXISTS `tks15`.`institution` (
    `ins_id` TINYINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '', 
    `ins_name` VARCHAR(75) NOT NULL COMMENT '', 
    `ins_street` VARCHAR(45) NOT NULL COMMENT '', 
    `ins_city` VARCHAR(45) NOT NULL COMMENT '', 
    `ins_state` VARCHAR(2) NOT NULL COMMENT '', 
    `ins_zip` INT UNSIGNED NOT NULL COMMENT '', 
    `ins_phone` BIGINT(10) UNSIGNED NOT NULL COMMENT '', 
    `ins_email` VARCHAR(100) NOT NULL COMMENT '', 
    `ins_url` VARCHAR(100) NOT NULL COMMENT '', 
    `ins_contact` VARCHAR(45) NOT NULL COMMENT '', 
    `ins_notes` VARCHAR(45) NULL COMMENT '', 
    PRIMARY KEY (`ins_id`) COMMENT '') 
ENGINE = InnoDB; 


-- ----------------------------------------------------- 
-- Table `tks15`.`account` 
-- ----------------------------------------------------- 
DROP TABLE IF EXISTS `tks15`.`account` ; 

CREATE TABLE IF NOT EXISTS `tks15`.`account` (
    `act_id` TINYINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '', 
    `act_type` VARCHAR(20) NOT NULL COMMENT '', 
    `act_notes` VARCHAR(255) NULL COMMENT '', 
    PRIMARY KEY (`act_id`) COMMENT '') 
ENGINE = InnoDB; 


-- ----------------------------------------------------- 
-- Table `tks15`.`user` 
-- ----------------------------------------------------- 
DROP TABLE IF EXISTS `tks15`.`user` ; 

CREATE TABLE IF NOT EXISTS `tks15`.`user` (
    `usr_id` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '', 
    `usr_fname` VARCHAR(45) NOT NULL COMMENT '', 
    `usr_lname` VARCHAR(45) NOT NULL COMMENT '', 
    `usr_street` VARCHAR(45) NOT NULL COMMENT '', 
    `usr_city` VARCHAR(45) NOT NULL COMMENT '', 
    `usr_state` VARCHAR(2) NOT NULL COMMENT '', 
    `usr_zip` INT UNSIGNED NOT NULL COMMENT '', 
    `usr_phone` BIGINT(10) UNSIGNED NULL COMMENT '', 
    `usr_email` VARCHAR(100) NULL COMMENT '', 
    `usr_notes` VARCHAR(255) NULL COMMENT '', 
    PRIMARY KEY (`usr_id`) COMMENT '') 
ENGINE = InnoDB; 


-- ----------------------------------------------------- 
-- Table `tks15`.`source` 
-- ----------------------------------------------------- 
DROP TABLE IF EXISTS `tks15`.`source` ; 

CREATE TABLE IF NOT EXISTS `tks15`.`source` (
    `src_id` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '', 
    `ins_id` TINYINT UNSIGNED NOT NULL COMMENT '', 
    `act_id` TINYINT UNSIGNED NOT NULL COMMENT '', 
    `usr_id` SMALLINT UNSIGNED NOT NULL COMMENT '', 
    `src_start_date` DATE NOT NULL COMMENT '', 
    `src_end_date` DATE NOT NULL COMMENT '', 
    `src_notes` VARCHAR(255) NULL COMMENT '', 
    PRIMARY KEY (`src_id`) COMMENT '', 
    INDEX `fk_source_institution1_idx` (`ins_id` ASC) COMMENT '', 
    INDEX `fk_source_account1_idx` (`act_id` ASC) COMMENT '', 
    INDEX `fk_source_user1_idx` (`usr_id` ASC) COMMENT '', 
    CONSTRAINT `fk_source_institution1` 
    FOREIGN KEY (`ins_id`) 
    REFERENCES `tks15`.`institution` (`ins_id`) 
    ON DELETE NO ACTION 
    ON UPDATE NO ACTION, 
    CONSTRAINT `fk_source_account1` 
    FOREIGN KEY (`act_id`) 
    REFERENCES `tks15`.`account` (`act_id`) 
    ON DELETE NO ACTION 
    ON UPDATE NO ACTION, 
    CONSTRAINT `fk_source_user1` 
    FOREIGN KEY (`usr_id`) 
    REFERENCES `tks15`.`user` (`usr_id`) 
    ON DELETE NO ACTION 
    ON UPDATE NO ACTION) 
ENGINE = InnoDB; 


-- ----------------------------------------------------- 
-- Table `tks15`.`transaction` 
-- ----------------------------------------------------- 
DROP TABLE IF EXISTS `tks15`.`transaction` ; 

CREATE TABLE IF NOT EXISTS `tks15`.`transaction` (
    `trn_id` MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '', 
    `src_id` SMALLINT UNSIGNED NOT NULL COMMENT '', 
    `cat_id` MEDIUMINT UNSIGNED NOT NULL COMMENT '', 
    `trn_type` ENUM('credit', 'debit') NOT NULL COMMENT '', 
    `trn_method` VARCHAR(15) NOT NULL COMMENT '', 
    `trn_amount` DECIMAL NOT NULL COMMENT '', 
    `trn_date` DATE NOT NULL COMMENT '', 
    `trn_time` TIMESTAMP NOT NULL COMMENT '', 
    `trn_notes` VARCHAR(255) NULL COMMENT '', 
    PRIMARY KEY (`trn_id`) COMMENT '', 
    INDEX `fk_transaction_category_idx` (`cat_id` ASC) COMMENT '', 
    INDEX `fk_transaction_source1_idx` (`src_id` ASC) COMMENT '', 
    CONSTRAINT `fk_transaction_category` 
    FOREIGN KEY (`cat_id`) 
    REFERENCES `tks15`.`category` (`cat_id`) 
    ON DELETE NO ACTION 
    ON UPDATE NO ACTION, 
    CONSTRAINT `fk_transaction_source1` 
    FOREIGN KEY (`src_id`) 
    REFERENCES `tks15`.`source` (`src_id`) 
    ON DELETE NO ACTION 
    ON UPDATE NO ACTION) 
ENGINE = InnoDB; 


SET [email protected]_SQL_MODE; 
SET [email protected]_FOREIGN_KEY_CHECKS; 
SET [email protected]_UNIQUE_CHECKS; 

-- ----------------------------------------------------- 
-- Data for table `tks15`.`category` 
-- ----------------------------------------------------- 
START TRANSACTION; 
USE `tks15`; 
INSERT INTO `tks15`.`category` (`cat_id`, `cat_type`, `cat_notes`) VALUES (DEFAULT, 'misc', 'Lorem ipsum dolor sit amet, nec vocent forensibus ei. Cu graeco copiosae vim, est veri dolorem placerat ne. Quaeque deterruisset ea qui,'); 
INSERT INTO `tks15`.`category` (`cat_id`, `cat_type`, `cat_notes`) VALUES (DEFAULT, 'tax return', 'Lorem ipsum dolor sit amet, nec vocent forensibus ei. Cu graeco copiosae vim, est veri dolorem placerat ne. Quaeque deterruisset ea qui,'); 
INSERT INTO `tks15`.`category` (`cat_id`, `cat_type`, `cat_notes`) VALUES (DEFAULT, 'investment', 'Lorem ipsum dolor sit amet, nec vocent forensibus ei. Cu graeco copiosae vim, est veri dolorem placerat ne. Quaeque deterruisset ea qui,'); 
INSERT INTO `tks15`.`category` (`cat_id`, `cat_type`, `cat_notes`) VALUES (DEFAULT, 'health', 'Lorem ipsum dolor sit amet, nec vocent forensibus ei. Cu graeco copiosae vim, est veri dolorem placerat ne. Quaeque deterruisset ea qui,'); 
INSERT INTO `tks15`.`category` (`cat_id`, `cat_type`, `cat_notes`) VALUES (DEFAULT, 'personal', 'Lorem ipsum dolor sit amet, nec vocent forensibus ei. Cu graeco copiosae vim, est veri dolorem placerat ne. Quaeque deterruisset ea qui,'); 

COMMIT; 


-- ----------------------------------------------------- 
-- Data for table `tks15`.`institution` 
-- ----------------------------------------------------- 
START TRANSACTION; 
USE `tks15`; 
INSERT INTO `tks15`.`institution` (`ins_id`, `ins_name`, `ins_street`, `ins_city`, `ins_state`, `ins_zip`, `ins_phone`, `ins_email`, `ins_url`, `ins_contact`, `ins_notes`) VALUES (, 'Goldman Sachs', '200 West St', 'New York', 'NY', 10001, 8507856541, '[email protected]', 'goldmansachs.com', '[email protected]', 'Lorem ipsum dolor sit amet, nec vocent forensibus ei. Cu graeco copiosae vim, est veri dolorem placerat ne. Quaeque deterruisset ea qui,'); 
INSERT INTO `tks15`.`institution` (`ins_id`, `ins_name`, `ins_street`, `ins_city`, `ins_state`, `ins_zip`, `ins_phone`, `ins_email`, `ins_url`, `ins_contact`, `ins_notes`) VALUES (, 'J.P Morgan', '270 Park Ave', 'New York', 'NY', 10001, 9874561478, '[email protected]', 'jpmorgan.com', '[email protected]', 'Lorem ipsum dolor sit amet, nec vocent forensibus ei. Cu graeco copiosae vim, est veri dolorem placerat ne. Quaeque deterruisset ea qui,'); 
INSERT INTO `tks15`.`institution` (`ins_id`, `ins_name`, `ins_street`, `ins_city`, `ins_state`, `ins_zip`, `ins_phone`, `ins_email`, `ins_url`, `ins_contact`, `ins_notes`) VALUES (, 'US Bank', '433 Hackensack St', 'Minneapolis', 'MN', 55401, 6321238795, '[email protected]', 'usbank.com', '[email protected]', 'Lorem ipsum dolor sit amet, nec vocent forensibus ei. Cu graeco copiosae vim, est veri dolorem placerat ne. Quaeque deterruisset ea qui,'); 
INSERT INTO `tks15`.`institution` (`ins_id`, `ins_name`, `ins_street`, `ins_city`, `ins_state`, `ins_zip`, `ins_phone`, `ins_email`, `ins_url`, `ins_contact`, `ins_notes`) VALUES (, 'Wells Fargo', '420 Montgomery St', 'San Francisco', 'CA', 94101, 8974561257, '[email protected]', 'wellsfargo.com', '[email protected]', 'Lorem ipsum dolor sit amet, nec vocent forensibus ei. Cu graeco copiosae vim, est veri dolorem placerat ne. Quaeque deterruisset ea qui,'); 
INSERT INTO `tks15`.`institution` (`ins_id`, `ins_name`, `ins_street`, `ins_city`, `ins_state`, `ins_zip`, `ins_phone`, `ins_email`, `ins_url`, `ins_contact`, `ins_notes`) VALUES (, 'Ally Financial', '17442 Herspania St', 'Detroit', 'MI', 48201, 7894584562, '[email protected]', 'ally.com', '[email protected]', 'Lorem ipsum dolor sit amet, nec vocent forensibus ei. Cu graeco copiosae vim, est veri dolorem placerat ne. Quaeque deterruisset ea qui,'); 
INSERT INTO `tks15`.`institution` (`ins_id`, `ins_name`, `ins_street`, `ins_city`, `ins_state`, `ins_zip`, `ins_phone`, `ins_email`, `ins_url`, `ins_contact`, `ins_notes`) VALUES (, 'PNC Financial Services', '523 Broadway St', 'Pittsburgh', 'PA', 15201, 4567821236, '[email protected]', 'pnc.com', '[email protected]', 'Lorem ipsum dolor sit amet, nec vocent forensibus ei. Cu graeco copiosae vim, est veri dolorem placerat ne. Quaeque deterruisset ea qui,'); 
INSERT INTO `tks15`.`institution` (`ins_id`, `ins_name`, `ins_street`, `ins_city`, `ins_state`, `ins_zip`, `ins_phone`, `ins_email`, `ins_url`, `ins_contact`, `ins_notes`) VALUES (, 'HSBC Bank USA', '107 Iris Glen Dr', 'Chicago', 'IL', 60290, 4569821287, '[email protected]', 'us.hsbc.com', '[email protected]', 'Lorem ipsum dolor sit amet, nec vocent forensibus ei. Cu graeco copiosae vim, est veri dolorem placerat ne. Quaeque deterruisset ea qui,'); 
INSERT INTO `tks15`.`institution` (`ins_id`, `ins_name`, `ins_street`, `ins_city`, `ins_state`, `ins_zip`, `ins_phone`, `ins_email`, `ins_url`, `ins_contact`, `ins_notes`) VALUES (, 'Suntrust Bank', '303 Peachstreet St', 'Atlanta', 'GA', 30301, 6983578520, '[email protected]', 'suntrust.com', '[email protected]', 'Lorem ipsum dolor sit amet, nec vocent forensibus ei. Cu graeco copiosae vim, est veri dolorem placerat ne. Quaeque deterruisset ea qui,'); 
INSERT INTO `tks15`.`institution` (`ins_id`, `ins_name`, `ins_street`, `ins_city`, `ins_state`, `ins_zip`, `ins_phone`, `ins_email`, `ins_url`, `ins_contact`, `ins_notes`) VALUES (, 'Capital One', '1680 Capital One Dr', 'Mclean', 'VA', 32145, 7533574655, '[email protected]', 'capitalone.com', '[email protected]', 'Lorem ipsum dolor sit amet, nec vocent forensibus ei. Cu graeco copiosae vim, est veri dolorem placerat ne. Quaeque deterruisset ea qui,'); 

COMMIT; 


-- ----------------------------------------------------- 
-- Data for table `tks15`.`account` 
-- ----------------------------------------------------- 
START TRANSACTION; 
USE `tks15`; 
INSERT INTO `tks15`.`account` (`act_id`, `act_type`, `act_notes`) VALUES (DEFAULT, 'saving', 'Lorem ipsum dolor sit amet, nec vocent forensibus ei. Cu graeco copiosae vim, est veri dolorem placerat ne. Quaeque deterruisset ea qui,'); 
INSERT INTO `tks15`.`account` (`act_id`, `act_type`, `act_notes`) VALUES (DEFAULT, 'checking', 'Lorem ipsum dolor sit amet, nec vocent forensibus ei. Cu graeco copiosae vim, est veri dolorem placerat ne. Quaeque deterruisset ea qui,'); 
INSERT INTO `tks15`.`account` (`act_id`, `act_type`, `act_notes`) VALUES (DEFAULT, 'mortgage', 'Lorem ipsum dolor sit amet, nec vocent forensibus ei. Cu graeco copiosae vim, est veri dolorem placerat ne. Quaeque deterruisset ea qui,'); 
INSERT INTO `tks15`.`account` (`act_id`, `act_type`, `act_notes`) VALUES (DEFAULT, 'investments', 'Lorem ipsum dolor sit amet, nec vocent forensibus ei. Cu graeco copiosae vim, est veri dolorem placerat ne. Quaeque deterruisset ea qui,'); 
INSERT INTO `tks15`.`account` (`act_id`, `act_type`, `act_notes`) VALUES (DEFAULT, 'mortgage', 'Lorem ipsum dolor sit amet, nec vocent forensibus ei. Cu graeco copiosae vim, est veri dolorem placerat ne. Quaeque deterruisset ea qui,'); 

COMMIT; 


-- ----------------------------------------------------- 
-- Data for table `tks15`.`user` 
-- ----------------------------------------------------- 
START TRANSACTION; 
USE `tks15`; 
INSERT INTO `tks15`.`user` (`usr_id`, `usr_fname`, `usr_lname`, `usr_street`, `usr_city`, `usr_state`, `usr_zip`, `usr_phone`, `usr_email`, `usr_notes`) VALUES (DEFAULT, 'John', 'Doe', '3803 Route 17', 'Berwen', 'IL', 60402, 7894562365, '[email protected]', NULL); 
INSERT INTO `tks15`.`user` (`usr_id`, `usr_fname`, `usr_lname`, `usr_street`, `usr_city`, `usr_state`, `usr_zip`, `usr_phone`, `usr_email`, `usr_notes`) VALUES (DEFAULT, 'Opal ', 'Dane', '9985 Highland Ave', 'Port Jefferson Station', 'NY', 11767, 4561234789, NULL, NULL); 
INSERT INTO `tks15`.`user` (`usr_id`, `usr_fname`, `usr_lname`, `usr_street`, `usr_city`, `usr_state`, `usr_zip`, `usr_phone`, `usr_email`, `usr_notes`) VALUES (DEFAULT, 'Peta ', 'Kayleen', '8151 Academy St', 'Chipoee', 'MA', 01020, NULL, '[email protected]', NULL); 
INSERT INTO `tks15`.`user` (`usr_id`, `usr_fname`, `usr_lname`, `usr_street`, `usr_city`, `usr_state`, `usr_zip`, `usr_phone`, `usr_email`, `usr_notes`) VALUES (DEFAULT, 'Brenda ', 'Delora', '9132 Poplar City', 'Salt Lake City', 'UT', 84119, NULL, NULL, NULL); 
INSERT INTO `tks15`.`user` (`usr_id`, `usr_fname`, `usr_lname`, `usr_street`, `usr_city`, `usr_state`, `usr_zip`, `usr_phone`, `usr_email`, `usr_notes`) VALUES (DEFAULT, 'Ozzie', 'Nonie', '1534 Berkshire Dr', 'Encino', 'CA', 91316, 4561237845, NULL, NULL); 
INSERT INTO `tks15`.`user` (`usr_id`, `usr_fname`, `usr_lname`, `usr_street`, `usr_city`, `usr_state`, `usr_zip`, `usr_phone`, `usr_email`, `usr_notes`) VALUES (DEFAULT, 'Brandon ', 'Jimmie', '7738 Durham Ct', 'Hartford', 'CT', 06106, 8974269876, '[email protected]', NULL); 

COMMIT; 


-- ----------------------------------------------------- 
-- Data for table `tks15`.`source` 
-- ----------------------------------------------------- 
START TRANSACTION; 
USE `tks15`; 
INSERT INTO `tks15`.`source` (`src_id`, `ins_id`, `act_id`, `usr_id`, `src_start_date`, `src_end_date`, `src_notes`) VALUES (DEFAULT, DEFAULT, DEFAULT, DEFAULT, '2015-10-10', '2015-10-11', 'Lorem ipsum dolor sit amet, nec vocent forensibus ei. Cu graeco copiosae vim, est veri dolorem placerat ne. Quaeque deterruisset ea qui,'); 
INSERT INTO `tks15`.`source` (`src_id`, `ins_id`, `act_id`, `usr_id`, `src_start_date`, `src_end_date`, `src_notes`) VALUES (DEFAULT, DEFAULT, DEFAULT, DEFAULT, '2015-10-11', '2015-10-12', 'Lorem ipsum dolor sit amet, nec vocent forensibus ei. Cu graeco copiosae vim, est veri dolorem placerat ne. Quaeque deterruisset ea qui,'); 
INSERT INTO `tks15`.`source` (`src_id`, `ins_id`, `act_id`, `usr_id`, `src_start_date`, `src_end_date`, `src_notes`) VALUES (DEFAULT, DEFAULT, DEFAULT, DEFAULT, '2015-10-13', '2015-10-14', 'Lorem ipsum dolor sit amet, nec vocent forensibus ei. Cu graeco copiosae vim, est veri dolorem placerat ne. Quaeque deterruisset ea qui,'); 
INSERT INTO `tks15`.`source` (`src_id`, `ins_id`, `act_id`, `usr_id`, `src_start_date`, `src_end_date`, `src_notes`) VALUES (DEFAULT, DEFAULT, DEFAULT, DEFAULT, '2015-10-15', '2015-10-16', 'Lorem ipsum dolor sit amet, nec vocent forensibus ei. Cu graeco copiosae vim, est veri dolorem placerat ne. Quaeque deterruisset ea qui,'); 
INSERT INTO `tks15`.`source` (`src_id`, `ins_id`, `act_id`, `usr_id`, `src_start_date`, `src_end_date`, `src_notes`) VALUES (DEFAULT, DEFAULT, DEFAULT, DEFAULT, '2015-10-17', '2015-10-18', 'Lorem ipsum dolor sit amet, nec vocent forensibus ei. Cu graeco copiosae vim, est veri dolorem placerat ne. Quaeque deterruisset ea qui,'); 

COMMIT; 


-- ----------------------------------------------------- 
-- Data for table `tks15`.`transaction` 
-- ----------------------------------------------------- 
START TRANSACTION; 
USE `tks15`; 
INSERT INTO `tks15`.`transaction` (`trn_id`, `src_id`, `cat_id`, `trn_type`, `trn_method`, `trn_amount`, `trn_date`, `trn_time`, `trn_notes`) VALUES (DEFAULT, DEFAULT, DEFAULT, 'credit', 'atm', 10.00, '2015-09-28', '11:59:59', 'Lorem ipsum dolor sit amet, nec vocent forensibus ei. Cu graeco copiosae vim, est veri dolorem placerat ne. Quaeque deterruisset ea qui,'); 
INSERT INTO `tks15`.`transaction` (`trn_id`, `src_id`, `cat_id`, `trn_type`, `trn_method`, `trn_amount`, `trn_date`, `trn_time`, `trn_notes`) VALUES (DEFAULT, DEFAULT, DEFAULT, 'credit', 'check ', 359.23, '2015-09-29', '08:23:12', 'Lorem ipsum dolor sit amet, nec vocent forensibus ei. Cu graeco copiosae vim, est veri dolorem placerat ne. Quaeque deterruisset ea qui,'); 
INSERT INTO `tks15`.`transaction` (`trn_id`, `src_id`, `cat_id`, `trn_type`, `trn_method`, `trn_amount`, `trn_date`, `trn_time`, `trn_notes`) VALUES (DEFAULT, DEFAULT, DEFAULT, 'debit', 'bank', 20.00, '2015-09-30', '06:00:58', 'Lorem ipsum dolor sit amet, nec vocent forensibus ei. Cu graeco copiosae vim, est veri dolorem placerat ne. Quaeque deterruisset ea qui,'); 
INSERT INTO `tks15`.`transaction` (`trn_id`, `src_id`, `cat_id`, `trn_type`, `trn_method`, `trn_amount`, `trn_date`, `trn_time`, `trn_notes`) VALUES (DEFAULT, DEFAULT, DEFAULT, 'credit', 'pos', 6.23, '2015-10-01', '07:12:16', 'Lorem ipsum dolor sit amet, nec vocent forensibus ei. Cu graeco copiosae vim, est veri dolorem placerat ne. Quaeque deterruisset ea qui,'); 
INSERT INTO `tks15`.`transaction` (`trn_id`, `src_id`, `cat_id`, `trn_type`, `trn_method`, `trn_amount`, `trn_date`, `trn_time`, `trn_notes`) VALUES (DEFAULT, DEFAULT, DEFAULT, 'debit', 'atm', 10.00, '2015-10-02', '08:23:56', 'Lorem ipsum dolor sit amet, nec vocent forensibus ei. Cu graeco copiosae vim, est veri dolorem placerat ne. Quaeque deterruisset ea qui,'); 
INSERT INTO `tks15`.`transaction` (`trn_id`, `src_id`, `cat_id`, `trn_type`, `trn_method`, `trn_amount`, `trn_date`, `trn_time`, `trn_notes`) VALUES (DEFAULT, DEFAULT, DEFAULT, 'debit', 'pos', 59.99, '2015-10-05', '09:15:01', 'Lorem ipsum dolor sit amet, nec vocent forensibus ei. Cu graeco copiosae vim, est veri dolorem placerat ne. Quaeque deterruisset ea qui,'); 
INSERT INTO `tks15`.`transaction` (`trn_id`, `src_id`, `cat_id`, `trn_type`, `trn_method`, `trn_amount`, `trn_date`, `trn_time`, `trn_notes`) VALUES (DEFAULT, DEFAULT, DEFAULT, 'credit', 'check', 423.25, '2015-10-06', '10:15:45', 'Lorem ipsum dolor sit amet, nec vocent forensibus ei. Cu graeco copiosae vim, est veri dolorem placerat ne. Quaeque deterruisset ea qui,'); 
INSERT INTO `tks15`.`transaction` (`trn_id`, `src_id`, `cat_id`, `trn_type`, `trn_method`, `trn_amount`, `trn_date`, `trn_time`, `trn_notes`) VALUES (DEFAULT, DEFAULT, DEFAULT, 'debit', 'transfer', 500.00, '2015-10-08', '05:45:12', 'Lorem ipsum dolor sit amet, nec vocent forensibus ei. Cu graeco copiosae vim, est veri dolorem placerat ne. Quaeque deterruisset ea qui,'); 
INSERT INTO `tks15`.`transaction` (`trn_id`, `src_id`, `cat_id`, `trn_type`, `trn_method`, `trn_amount`, `trn_date`, `trn_time`, `trn_notes`) VALUES (DEFAULT, DEFAULT, DEFAULT, 'debit', 'bank', 5.00, '2015-10-09', '11:59:59', 'Lorem ipsum dolor sit amet, nec vocent forensibus ei. Cu graeco copiosae vim, est veri dolorem placerat ne. Quaeque deterruisset ea qui,'); 
INSERT INTO `tks15`.`transaction` (`trn_id`, `src_id`, `cat_id`, `trn_type`, `trn_method`, `trn_amount`, `trn_date`, `trn_time`, `trn_notes`) VALUES (DEFAULT, DEFAULT, DEFAULT, 'credit', 'pos', 1.23, '2015-10-10', '12:42:45', 'Lorem ipsum dolor sit amet, nec vocent forensibus ei. Cu graeco copiosae vim, est veri dolorem placerat ne. Quaeque deterruisset ea qui,'); 

COMMIT; 

и вот код ошибки

ERROR: Error 1452: Cannot add or update a child row: a foreign key constraint fails (`tks15`.`source`, CONSTRAINT `fk_source_institution1` FOREIGN KEY (`ins_id`) REFERENCES `institution` (`ins_id`) ON DELETE NO ACTION ON UPDATE NO ACTION) 
SQL Code: 
     INSERT INTO `tks15`.`source` (`src_id`, `ins_id`, `act_id`, `usr_id`, `src_start_date`, `src_end_date`, `src_notes`) VALUES (DEFAULT, DEFAULT, DEFAULT, DEFAULT, '2015-10-10', '2015-10-11', 'Lorem ipsum dolor sit amet, nec vocent forensibus ei. Cu graeco copiosae vim, est veri dolorem placerat ne. Quaeque deterruisset ea qui,') 

ответ

0

при вставке в «источник» таблицы, столбец «ins_id» должен иметь значение уже присутствует в колонке «ins_id» в таблице «учреждение» .. ... DEFAULT здесь не используется

0

Похоже, вы используете AUTO_INCREMENT для столбца ins_id таблицы institution.

Итак, ваше первое учреждение будет иметь значение 1, затем второе и id 2 и так далее.

Но при вставке в таблицу source вы используете DEFAULT для ins_id, который будет принимать значение 0.

Следовательно, ограничение внешнего ключа не выполняется.

+0

Итак, что вы предлагаете мне сделать в таблице заведений, чтобы гарантировать, что значения Auto increment несут в исходную таблицу? Должен ли я что-то изменить в коде или изменить что-то в столбце исходной таблицы? Раньше у меня никогда не было этой проблемы. –