2017-05-20 10 views
0

私持っているテーブルと呼ばれる履歴書ここ外部キー/カスケードは、テーブルに削除、追加することはできません(エラーなし)

は、そのテーブルのエクスポートです:

CREATE TABLE `resumes` (
    `id` int(10) UNSIGNED NOT NULL, 
    `title` varchar(100) COLLATE utf8_unicode_ci NOT NULL, 
    `province_id` int(10) UNSIGNED NOT NULL, 
    `city_id` int(10) UNSIGNED NOT NULL, 
    `name` char(100) COLLATE utf8_unicode_ci NOT NULL, 
    `last_name` char(100) COLLATE utf8_unicode_ci NOT NULL, 
    `email` char(50) COLLATE utf8_unicode_ci NOT NULL, 
    `mobile` char(255) COLLATE utf8_unicode_ci NOT NULL, 
    `phone` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, 
    `address` char(200) COLLATE utf8_unicode_ci NOT NULL, 
    `confirm` tinyint(1) NOT NULL DEFAULT '0', 
    `image` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, 
    `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, 
    `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, 
    `deleted_at` timestamp NULL DEFAULT NULL, 
    `gender` tinyint(1) NOT NULL DEFAULT '0', 
    `bdate` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL, 
    `marrieg` tinyint(1) NOT NULL DEFAULT '0', 
    `military_service` tinyint(1) NOT NULL DEFAULT '0', 
    `text` text COLLATE utf8_unicode_ci, 
    `password` varchar(100) COLLATE utf8_unicode_ci NOT NULL, 
    `token` varchar(100) COLLATE utf8_unicode_ci NOT NULL 
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; 

-- 
-- Indexes for dumped tables 
-- 

-- 
-- Indexes for table `resumes` 
-- 
ALTER TABLE `resumes` 
    ADD PRIMARY KEY (`id`), 
    ADD UNIQUE KEY `email` (`email`), 
    ADD UNIQUE KEY `mobile` (`mobile`); 

-- 
-- AUTO_INCREMENT for dumped tables 
-- 

-- 
-- AUTO_INCREMENT for table `resumes` 
-- 
ALTER TABLE `resumes` 
    MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT; 

私はforignを追加したいresume_researches `と呼ばれる別のテーブルを持っていますキー制約およびカスケードは、(参照履歴書テーブル)私はここにこのコード

ALTER TABLE resume_researches 
    ADD CONSTRAINT `fk_resumes_resume_researches` 
    FOREIGN KEY (`resume_id`) 
    REFERENCES `resumes` (`id`) 
    ON DELETE CASCADE ; 

を実行し、このテーブルに削除出力

です
MySQL returned an empty result set (i.e. zero rows). (Query took 0.0150 seconds.) 
ALTER TABLE resume_researches ADD CONSTRAINT `fk_resumes_resume_researches` FOREIGN KEY (`resume_id`) REFERENCES `resumes` (`id`) ON DELETE CASCADE 

しかし、私はここに、このテーブルをエクスポートする際のphpMyAdminにそこには関係のビューがありませんし、その結果

CREATE TABLE `resume_researches` (
    `id` int(11) NOT NULL, 
    `resume_id` int(11) UNSIGNED NOT NULL, 
    `title` varchar(100) COLLATE utf8_persian_ci NOT NULL, 
    `text` text COLLATE utf8_persian_ci NOT NULL, 
    `date` varchar(50) COLLATE utf8_persian_ci NOT NULL 
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_persian_ci; 

-- 
-- Indexes for dumped tables 
-- 

-- 
-- Indexes for table `resume_researches` 
-- 
ALTER TABLE `resume_researches` 
    ADD PRIMARY KEY (`id`), 
    ADD KEY `fk_resumes_resume_researches` (`resume_id`); 

-- 
-- AUTO_INCREMENT for dumped tables 
-- 

-- 
-- AUTO_INCREMENT for table `resume_researches` 
-- 
ALTER TABLE `resume_researches` 
    MODIFY `id` int(11) NOT NULL AUTO_INCREMENT; 

いただきました!間違っていますか?なぜ構造内にresumesテーブルへの参照がないのですか?

答えて

1

FOREIGN KEYs MyISAMでは機能しません。代わりにInnoDBを使用してください。

可変長の列にはCHARを使用しないでください。 VARCHARを使用してください。

照合を混同しないでください(utf8_unicode_ciとutf8_persian_ci)。 (大丈夫ですが、おそらくここにはない場合があります)

関連する問題