我需要为我的审阅者表创建一个外键。 我的主键是Reviewers_Id,我想把它从Reviewrs_POS表传递到Id_r1。。在
import MySQLdb as mdb
import sys
conexao = mdb.connect('localhost', 'root', 'rot', 'DbOmelete')
with conexao:
cur = conexao.cursor()
cur.execute("CREATE TABLE IF NOT EXISTS Reviewers(Reviewers_Id int unsigned not null AUTO_INCREMENT, PRIMARY KEY (Reviewers_Id),Title varchar(500), Polarity INT, Review TEXT);")
cur.execute("CREATE TABLE IF NOT EXISTS Reviewers_POS(ReviewersPOS_Id int unsigned not null PRIMARY KEY AUTO_INCREMENT, Review_POS TEXT,id_r1 integer,CONSTRAINT fk_id FOREIGN KEY (id_r1) REFERENCES Reviewers (Reviewers_Id));")
在__ 我得到了这个错误:
回溯(最近一次呼叫):
^{pr2}$有人知道怎么解决吗?我在想我错过了什么。。因为我真的不知道错误在哪里。。在
您的主键是
int unsigned
类型,而外键是integer
类型,两者不兼容。将外键更改为int unsigned
,表将成功创建。在{a1}
相关问题 更多 >
编程相关推荐