所以我只测试了一件事,制作了下表。
# 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,还是我的数据库模型错了?