对于相同的代码片段,SQLAlchemy 在 Mac OX 上创建外键约束,但是,它无法在 Debian Linux 上创建外键约束。
环境与图书馆:
蟒蛇 2.7
SQLAlchemy 0.7.8
MySQL-python-1.2.3 [这是连接器,我怀疑这里有问题]
代码片段:
class PRStatusCV(globalBase):
__tablename__ = 'pr_status_cv'
pr_status_cv_id = Column(Integer, primary_key=True)
name = Column(VARCHAR(100), nullable=False, unique=True)
def __init__(self, id, name, desc):
self.pr_status_cv_id = id
self.name = name
self.description = desc
class PhysicalRun(globalBase):
__tablename__ = 'prs'
pr_id = Column(Integer, primary_key=True)
run_name = Column(VARCHAR(200), nullable=False, unique=True)
pr_status_cv_id = Column(Integer, ForeignKey('pr_status_cv.pr_status_cv_id'))
def __init__(self, name, status):
self.run_name = name
self.pr_status_cv_id = status
在 Debian Linux 中,创建的表包含:
CREATE TABLE `prs` (
`pr_id` int(11) NOT NULL AUTO_INCREMENT,
`run_name` varchar(200) NOT NULL,
`pr_status_cv_id` int(11) DEFAULT NULL,
PRIMARY KEY (`pr_id`),
UNIQUE KEY `run_name` (`run_name`),
KEY `pr_status_cv_id` (`pr_status_cv_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 |
在 Mac OSX 中,创建的表如下所示:
CREATE TABLE `prs` (
`pr_id` int(11) NOT NULL AUTO_INCREMENT,
`run_name` varchar(200) NOT NULL,
`pr_status_cv_id` int(11) DEFAULT NULL,
PRIMARY KEY (`pr_id`),
UNIQUE KEY `run_name` (`run_name`),
KEY `pr_status_cv_id` (`pr_status_cv_id`),
CONSTRAINT `prs_ibfk_1` FOREIGN KEY (`pr_status_cv_id`) REFERENCES `pr_status_cv` (`pr_status_cv_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
观察:Mac OSX SQLAlchemy 似乎默认选择了 InnoDB DB Engine,而 Debian 选择了 MyISAM。知道为什么会这样吗?
我需要进行哪些修改才能有约束 -CONSTRAINT `prs_ibfk_1` FOREIGN KEY (`pr_status_cv_id`) REFERENCES `pr_status_cv`
而不仅仅是KEY `pr_status_cv_id` (`pr_status_cv_id`)
?
我的 Debian Python 部署有什么问题吗?