Schema Export doesn't count foreign key dependencies

Discussion of open issues, suggestions and bugs regarding database management and administration tools for MySQL
Post Reply
ruslanv
Posts: 4
Joined: Sat 12 Apr 2008 00:25

Schema Export doesn't count foreign key dependencies

Post by ruslanv » Sat 12 Apr 2008 00:32

Hi guys. I have version 2.10.79 (just purchased actually).

It's not really bug but more of a lack of implementaton which kills the feature. The problem is that Schema Export doesn't count on foreign key dependencies. In my case I have DB which contains information about different tests. So I have tables with test information, table of questions and finally table which contains answers. Here is script created by MyDeveloper Studio:

Code: Select all

-- 
-- Table structure for table test_answers
-- 
create table `test_answers` (
  `question_id` bigint(20) not null auto_increment,
  `position` int(11) not null,
  `text` varchar(1024) not null,
  `is_right_answer` tinyint(1) not null default '0' comment 'Determines right answer(s) on the question',
  `has_picture` tinyint(1) not null default '0',
  primary key (`question_id`,`position`),
  constraint `question_id` foreign key (`question_id`) references `test_questions` (`id`)
) engine=innodb auto_increment=2 default charset=utf8;

-- 
-- Table structure for table test_questions
-- 
create table `test_questions` (
  `id` bigint(20) not null auto_increment,
  `test_id` bigint(20) not null,
  `position` int(11) not null,
  `name` varchar(1024) not null,
  `has_picture` tinyint(1) not null,
  primary key (`id`),
  unique key `test_id_position` (`test_id`,`position`),
  constraint `test_id` foreign key (`test_id`) references `tests` (`id`)
) engine=innodb auto_increment=3 default charset=utf8;

-- 
-- Table structure for table tests
-- 
create table `tests` (
  `id` bigint(20) not null auto_increment,
  `owner_id` bigint(20) not null,
  `name` varchar(256) not null,
  `subject_id` int(11) not null,
  `sub_subject_id` int(11) not null,
  `access_id` tinyint(4) not null,
  primary key (`id`),
  key `access_id` (`access_id`),
  key `subject_id` (`subject_id`),
  key `owner_id` (`owner_id`),
  constraint `access_id` foreign key (`access_id`) references `access_types` (`id`),
  constraint `owner_id` foreign key (`owner_id`) references `users` (`id`),
  constraint `subject_id` foreign key (`subject_id`) references `subject_types` (`id`)
) engine=innodb auto_increment=2 default charset=utf8;
As I you see creation of `test_answers` will fail simply because referenced `test_questions` is not created yet.

So MyDeveloper Studio should export schema script in order these objects were created.

Thank you.

Duke
Devart Team
Posts: 476
Joined: Fri 29 Oct 2004 09:25

Post by Duke » Mon 14 Apr 2008 07:02

This problem is removed by turning 'Disable Keys' option on. Unfortunately, this option is disabled in 'Structure' mode (we'll correct this). Use 'Structure and Data' mode.

Duke
Devart Team
Posts: 476
Joined: Fri 29 Oct 2004 09:25

Post by Duke » Mon 14 Apr 2008 08:06

Sorry, I was wrong about 'Disable Keys' option. Schema Export always generates following control comment
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */

This comment will allow your script to execute successfully. But your server version must be equal or higher than 4.0.14.

Post Reply