Mysql创建外键

2024-05-14 03:36:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要为我的审阅者表创建一个外键。 我的主键是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}$

有人知道怎么解决吗?我在想我错过了什么。。因为我真的不知道错误在哪里。。在


Tags: keyposimportidexecuteifcreatetable