1
CREATE TABLE `defendant_company_potential` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `company_name` varchar(100) NOT NULL,
  `address` varchar(100) DEFAULT NULL,
  `city` varchar(50) DEFAULT NULL,
  `state` varchar(4) DEFAULT NULL,
  `zip` varchar(20) DEFAULT NULL,
  `email` varchar(50) DEFAULT NULL,

  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_defendant_potential_company` (`company_name`,`address`,`city`,`state`),
  KEY `fk_jurisdiction_company` (`jurisdiction_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


CREATE TABLE `defendant_defendant_company_potential_map` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `defendant_id` int(11) NOT NULL,
  `defendant_company_potential_id` int(11) NOT NULL,
  `defendant_company_potential_correspondance_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_defendant_defendant_company`
  (`defendant_id`,`defendant_company_potential_id`),
  CONSTRAINT `defendant_id_fk_map` FOREIGN KEY (`defendant_id`) REFERENCES `defendant`(`id`),
  CONSTRAINT `defendant_company_potential_id_fk_map` FOREIGN KEY (`defendant_company_potential_id`) REFERENCES `defendant_company_potential`(`id`)
  CONSTRAINT `defendant_company_potential_correspondance_id_fk` FOREIGN KEY (`defendant_company_potential_correspondance_id`) REFERENCES `defendant_company_potential_correspondance`(`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


CREATE TABLE `defendant_company_potential_correspondance` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `defendant_id` int(11) NOT NULL,
  `defendant_company_potential_id` int(11) NOT NULL,
  `mailed_count` int(11) DEFAULT NULL,
  `phoned_date` datetime DEFAULT NULL,
 PRIMARY KEY (`id`),
  UNIQUE KEY `uk_potential_correspondance`     (`defendant_id`,`defendant_company_potential_id`),
  CONSTRAINT `defendant_id_fk` FOREIGN KEY (`defendant_id`) REFERENCES `defendant`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `defendant_company_potential_id_fk` FOREIGN KEY (`defendant_company_potential_id`)
  REFERENCES `defendant_company_potential`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) 

被告表只有一个字段名,PK是它的ID。

我的问题是我应该如何在 Django 中制作该地图表(我无法更改表结构)???谢谢

4

1 回答 1

2

查看集成现有数据库的文档

看起来您应该能够创建数据库表,然后让 django 检查它并创建模型。

python manage.py inspectdb > models.py
于 2012-09-21T09:04:42.857 回答