我需要為我的Reviewers_POS表創(chuàng)建一個外鍵。我將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));")__我收到此錯誤:追溯(最近一次通話): File "SQLTesteForeign.py", line 14, in <module> 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) ON DELETE NO ACTION ON UPDATE NO ACTION);") File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 174, in execute self.errorhandler(self, exc, value) File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler raise errorclass, errorvalue_mysql_exceptions.OperationalError: (1005, "Can't create table 'DbOmelete.Reviewers_POS' (errno: 150)")有人知道如何解決嗎?我以為我想念某物..因為我真的不知道“哪里”是錯誤..
1 回答

森林海
TA貢獻2011條經驗 獲得超2個贊
您的主鍵是類型int unsigned
,而您的外鍵是類型integer
,兩者是不兼容的。將您的外鍵更改為int unsigned
,表將成功創(chuàng)建。
添加回答
舉報
0/150
提交
取消