そこで、次の表を作成して、1 つのことをテストしました。
# Dump of table driverclass
# ------------------------------------------------------------
CREATE TABLE `driverclass` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
# Dump of table event
# ------------------------------------------------------------
CREATE TABLE `event` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
# Dump of table driver
# ------------------------------------------------------------
CREATE TABLE `driver` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
# Dump of table driver_driverclass_event
# ------------------------------------------------------------
CREATE TABLE `driver_driverclass_event` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`driver_id` int(11) unsigned DEFAULT NULL,
`event_class_id` int(11) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `driver_id` (`driver_id`),
KEY `event_class_id` (`event_class_id`),
CONSTRAINT `driver_driverclass_event_ibfk_2` FOREIGN KEY (`event_class_id`) REFERENCES `driverclass_event` (`id`),
CONSTRAINT `driver_driverclass_event_ibfk_1` FOREIGN KEY (`driver_id`) REFERENCES `driver` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
# Dump of table driverclass_event
# ------------------------------------------------------------
CREATE TABLE `driverclass_event` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`event_id` int(11) unsigned DEFAULT NULL,
`driverclass_id` int(11) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `event_id` (`event_id`),
KEY `driverclass_id` (`driverclass_id`),
CONSTRAINT `driverclass_event_ibfk_2` FOREIGN KEY (`driverclass_id`) REFERENCES `driverclass` (`id`),
CONSTRAINT `driverclass_event_ibfk_1` FOREIGN KEY (`event_id`) REFERENCES `event` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
に関する関係であるべきですManyToManyField
。ただし、Djangos
inspectdb
ForeignKeys のトンを持つ 5 つのモデルとしてそれを見てください。Djangos
inspectdb
ManyToManyFields を考慮していませんか、それともデータベース モデルが間違っていますか?