Reviewers_POS テーブルの外部キーを作成する必要があります。Reviewers_Id を主キーとして持っており、それを Reviewers_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)")
誰かがそれを解決する方法を知っていますか? 私は何かが足りないと思っています..「どこ」がエラーなのか本当にわからないからです..