对于同样的代码片段,SQLAlchemy 在 Mac OX 上创建了外键约束,但在 Debian Linux 上无法创建外键约束。
环境和库:
Python 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部署有问题吗?