Py学习  »  DATABASE

创建表时出现php mysql“unique”错误

Bitsnack • 4 年前 • 563 次点击  

所以我有这个:

CREATE TABLE activeSessions (
    id VARCHAR NOT NULL UNIQUE,
    claimtime int,
    mp FLOAT
);

当我把这个放到数据库中时,会出现:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'NOT NULL UNIQUE,
    claimtime int,
    mp FLOAT
)' at line 2

我该怎么解决这个问题?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/38079
 
563 次点击  
文章 [ 1 ]  |  最新文章 4 年前
Alberto
Reply   •   1 楼
Alberto    5 年前

您需要在列声明之后指定约束:

CREATE TABLE activeSessions (
    id VARCHAR(10) NOT NULL,
    claimtime int,
    mp FLOAT,
    UNIQUE(id)
);

记住给varchar列一个int值。