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 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 matlab解优化问题代码
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导
  • ¥15 docker模式webrtc-streamer 无法播放公网rtsp
  • ¥15 学不会递归,理解不了汉诺塔参数变化
  • ¥15 基于图神经网络的COVID-19药物筛选研究
  • ¥30 软件自定义无线电该怎样使用
  • ¥15 R语言mediation包做中介分析,直接效应和间接效应都很小,为什么?