创建表时出现MySQL语法错误 [英] Mysql Syntax error on creating table

查看:64
本文介绍了创建表时出现MySQL语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在docker容器中有一个MySQL数据库.入口点执行创建数据库的脚本和创建表的脚本.

I have a MySQL database inside a docker container. The entrypoint executes a script creating the database and a script creating tables.

除一张桌子外,其他所有东西都可以正常工作.

Everything works fine except for one table.

use db;

... creating other tables

CREATE TABLE mediametadata
(
id bigint not null  primary key,
title VARCHAR not NULL,
artist VARCHAR not NULL,
album VARCHAR,
releaseYear bigint,
mediaId bigint NOT NULL,
constraint fk__pk_metadata_objectid
        foreign key (id) references objectid (id),

constraint fk__metadata_media_id
        foreign key (mediaId) references media (id)
)
;

记录到控制台的错误是

mysql_1  | ERROR 1064 (42000) at line 150: 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 'not NULL,
mysql_1  | artist VARCHAR not NULL,
mysql_1  | album VARCHAR,
mysql_1  | releaseYear bigint,
mysql_1  | mediaId bi' at line 4

第150行是 CREATE TABLE mediametadata

  • MySQL版本:8.0.3-rc-log
  • 主机操作系统:Debian jessie

我开始认为 year metadata 可能是保留关键字,因此我重命名了表和 year 列,但错误仍然存​​在./p>

I came to think year and metadata might be reserved keywords so I renamed the table and the year column but the error persists.

推荐答案

@Bill Karwin在第一条评论中回答Varchar需要长度[Varchar(number)]

answered by @Bill Karwin in first comment Varchar needs length [Varchar(number)]

这篇关于创建表时出现MySQL语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆