V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
MySQL 5.5 Community Server
MySQL 5.6 Community Server
Percona Configuration Wizard
XtraBackup 搭建主从复制
Great Sites on MySQL
Percona
MySQL Performance Blog
Severalnines
推荐管理工具
Sequel Pro
phpMyAdmin
推荐书目
MySQL Cookbook
MySQL 相关项目
MariaDB
Drizzle
参考文档
http://mysql-python.sourceforge.net/MySQLdb.html
smoker
V2EX  ›  MySQL

疯掉了。。。谁来告诉我,这段到底错在哪?

  •  
  •   smoker · 2012-07-07 19:25:00 +08:00 · 2813 次点击
    这是一个创建于 4282 天前的主题,其中的信息可能已经有所发展或是发生改变。
    CREATE TABLE `users` (
    `id` int(11) NOT NULL auto_increment,
    `username` varchar(100) NOT NULL,
    `password` varchar(35) NOT NULL,
    `groupid` int(11) NOT NULL,
    `groupname` varchar(100) NOT NULL,
    `phone` varchar(35),
    `introduction` varchar(255),
    PRIMARY KEY (`id`),
    UNIQUE KEY `username` (`username`),
    CONSTRAINT FOREIGN KEY ('groupid', 'groupname')
    REFERENCES group ('id', 'groupname')
    ON DELETE RESTRICT
    ON UPDATE CASCADE
    )ENGINE=InnoDB DEFAULT CHARSET=utf8;




    ERROR 1064 (42000): 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 ''groupid', 'groupname')
    REFERENCES group ('id', 'groupname')
    ON DELETE RESTRICT
    5 条回复    1970-01-01 08:00:00 +08:00
    fanzeyi
        1
    fanzeyi  
       2012-07-07 19:34:57 +08:00   ❤️ 1
    CONSTRAINT FOREIGN KEY (`groupid`, `groupname`)
    REFERENCES `group` (`id`, `groupname`)

    试试
    smoker
        2
    smoker  
    OP
       2012-07-07 19:35:47 +08:00
    沉的好快。。。
    那我说明下。。

    问题出在

    CONSTRAINT FOREIGN KEY ('groupid', 'groupname')
    REFERENCES group ('id', 'groupname')
    ON DELETE RESTRICT
    ON UPDATE CASCADE

    这段上,其中group是需要链接的表, id是PRIMARY KEY, groupname是UNIQUE KEY
    然后……然后就出错了。。。
    smoker
        3
    smoker  
    OP
       2012-07-07 19:39:57 +08:00
    居然成了。。。。谢谢!!!

    奇怪明明刚才自己加''了也不行。。。总之复制你这个好了。。
    qdvictory
        4
    qdvictory  
       2012-07-07 19:42:17 +08:00
    @smoker 那不是'号,而是`号
    fanzeyi
        5
    fanzeyi  
       2012-07-07 20:01:18 +08:00
    @smoker ` 号是 键盘左上角 ESC 下面 1 左边的那个按钮
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1017 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 19:24 · PVG 03:24 · LAX 12:24 · JFK 15:24
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.