背景: 建立一个数据库mydb, 含有一个表employee, employee_single通过id外键关联,实现删除employee记录关联删除employee_single对应的记录。刷出orm, 实现修改orm后可以自动将表修改部分刷回数据库。
一、mysql表设计
建库:
CREATE DATABASE mydb;
建表:employee
、employee_single
CREATE TABLE `employee` (
`PID` int(11) unsigned NOT NULL AUTO_INCREMENT,
`ID` varchar(64) DEFAULT NULL COMMENT 'this is employee id',
`Name` varchar(64) NOT NULL DEFAULT '' COMMENT 'this is employee name',
`UpdateTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`Extend0` varchar(100) DEFAULT NULL,
PRIMARY KEY (`PID`),
UNIQUE KEY `id_idx` (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=800 DEFAULT CHARSET=utf8;
CREATE TABLE `employee_single` (
`PID` int(11) unsigned NOT NULL AUTO_INCREMENT,
`ID` varchar(64) NOT NULL DEFAULT '' COMMENT 'this is employee id',
`addr` varchar(64) NOT NULL DEFAULT '' COMMENT 'this is employee addr',
`age` int(11) NOT NULL DEFAULT '0' COMMENT 'this is employee age',
PRIMARY KEY (`PID`),
UNIQUE KEY `id_idx` (`ID&#