这个 mysql 查询有什么问题?
这有效:
CREATE TABLE shoutbox_shout (
shout_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
user_id INT UNSIGNED NOT NULL DEFAULT 0,
shout_date INT UNSIGNED NOT NULL DEFAULT 0,
message MEDIUMTEXT NOT NULL,
KEY shout_date (shout_date)
)
...而这:
CREATE TABLE shoutbox_shout (
shout_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
user_id INT UNSIGNED NOT NULL DEFAULT 0,
shout_date INT UNSIGNED NOT NULL DEFAULT 0,
message MEDIUMTEXT NOT NULL,
KEY shout_date (shout_date)
)
...结果:
错误代码:1075 - 表定义不正确;只能有一个自动列,并且必须将其定义为键
我添加了主键,但仍然出现错误。
This works:
CREATE TABLE shoutbox_shout (
shout_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
user_id INT UNSIGNED NOT NULL DEFAULT 0,
shout_date INT UNSIGNED NOT NULL DEFAULT 0,
message MEDIUMTEXT NOT NULL,
KEY shout_date (shout_date)
)
...while this:
CREATE TABLE shoutbox_shout (
shout_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
user_id INT UNSIGNED NOT NULL DEFAULT 0,
shout_date INT UNSIGNED NOT NULL DEFAULT 0,
message MEDIUMTEXT NOT NULL,
KEY shout_date (shout_date)
)
...results in:
Error Code: 1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key
I added primary key but still get error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
引用 Bug #45987,错误 1075 (42000):表定义不正确:
MyISAM 不再是默认引擎; InnoDB 是。
另外:http://bugs.mysql.com/bug.php?id=60104
结论
InnoDB 不支持 AUTO_INCRMENT,但没有为表定义主键,但 MyISAM 支持。选择要使用的引擎(MyISAM 或 InnoDB),并相应地处理 CREATE TABLE 语句。
Quote Bug #45987, ERROR 1075 (42000): Incorrect table definition:
MyISAM is no longer the default engine; InnoDB is.
Also: http://bugs.mysql.com/bug.php?id=60104
Conclusion
InnoDB doesn't support AUTO_INCREMENT but no primary key being defined for the table, but MyISAM does. Choose which engine (MyISAM or InnoDB) you want to use, and deal with the CREATE TABLE statement accordingly.
好吧,我不是mysql专家,但是
shout_id INT UNSIGNED NOT NULL AUTO_INCRMENT
是一个自动增量,没有定义为Key....
考虑到我们在这个业务中遇到的许多不清楚或误导性的错误消息,我无法想象一个更清晰的错误消息错误信息 ....
Well I'm not a mysql expert, but
shout_id INT UNSIGNED NOT NULL AUTO_INCREMENT
is an auto increment, not defined as Key....
Given the many unclear or misleading error messages we experience in this business, I can't imagine a clearer error message ....
+1用于使用无符号等..但你说...它不能为空...但默认情况下它是0..对我来说0总是为空?并且 auto_increment 的主键永远不会为空。
你的方向很好,但要这样做:
+1 for using unsigned etc.. but you say... it can be not null... BUT by default its 0.. and for me is 0 always null ? and a primary key thats auto_increment is NEVER null..
Your pretty in the good direction but do it this way:
@Brandon_R:我使用 MySQL 5.0.67-community-nt 的命令行得到了同样的错误,但使用这样的代码可以工作——
@Brandon_R: I get the same error using command line of MySQL 5.0.67-community-nt, using the code like this works though --
您必须将 auto_increment 列定义为主键/键
,或者
您还应该定义您的引擎类型 - 我推荐 innodb。
很高兴看到您使用无符号整数数据类型而不指定愚蠢的可选显示宽度!
you MUST define an auto_increment column as a primary key/key
or
You should also define your engine type - i would recommend innodb.
Nice to see you using unsigned integer datatypes without specifying silly optional display widths !!
这个错误不是简洁地解释了这一点吗? AUTO_INCRMENT 列(如果有的话)必须是键列。
正如您所演示的,这样做可以解决问题。
Doesn't the error explain this succinctly? The AUTO_INCREMENT column — if you have one — must be a key column.
As you demonstrate, making it so fixes the problem.