donte1234567 2014-12-28 21:09
浏览 68
已采纳

创建表时出错:键列不存在[重复]

This question is an exact duplicate of:

I tried create these tables:

$sql = "CREATE TABLE IF NOT EXISTS Articls (
            id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,     
            name VARCHAR(254) COLLATE utf8_persian_ci NOT NULL      
) DEFAULT COLLATE utf8_persian_ci";



$sql = "CREATE TABLE IF NOT EXISTS Tags (
            id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,  
            id_articls INT(10) UNSIGNED NOT NULL,   
            name VARCHAR(256) COLLATE utf8_persian_ci NOT NULL,           
            FOREIGN KEY (`Tags.id_articls`) REFERENCES Articls(`Articls.id`)
) DEFAULT COLLATE utf8_persian_ci"

;

First table create successfully but secnond I get this error:

Error creating table: Key column 'Tags.id_articls' doesn't exist in table

If I remove Tags. in Tags.id_articls and Tags.id_articls I get errno: 150

Also If I try

   $sql = "CREATE TABLE IF NOT EXISTS Tags (
                id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,  
                id_articls INT(10) UNSIGNED NOT NULL,   
                name VARCHAR(256) COLLATE utf8_persian_ci NOT NULL,           
                FOREIGN KEY (Tags.id_articls) REFERENCES Articls(Articls.id)
    ) DEFAULT COLLATE utf8_persian_ci"

I get this error:

Error creating table: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.id_articls) REFERENCES Articls(Articls.id) ) DEFAULT COLLATE utf8_persian_ci' at line 5

</div>
  • 写回答

1条回答 默认 最新

  • duan02468 2014-12-28 21:13
    关注

    The foreign key in your Tags table should be id_articls and not Tags.id_articls

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程