MySQL phpMyAdmin - “请输入有效长度”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40708324/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
phpMyAdmin - "Please enter a valid length"
提问by Nicholas Hassan
I'm trying to create a table in phpMyAdmin, and I keep getting the same error no matter how I manipulate the SQL code. This is the preview SQL that phpMyAdmin generates
我正在尝试在 phpMyAdmin 中创建一个表,无论我如何操作 SQL 代码,我都会遇到相同的错误。这是phpMyAdmin生成的预览SQL
CREATE TABLE `puppies`.`animals` (
`id` INT(11) NOT NULL AUTO_INCREMENT ,
`puppy_name` VARCHAR(256) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`breed_id` INT(11) NOT NULL ,
`description` VARCHAR(256) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`price` DECIMAL(10,2) NOT NULL ,
`picture_url` VARCHAR(256) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`sold` TINYINT(1) NOT NULL ,
PRIMARY KEY (`id`)
) ENGINE = InnoDB;
I've tried it with multiple variations of brackets and commas.
我已经尝试过使用括号和逗号的多种变体。
回答by Pjottur
To those still experiencing this, and don't want to wait for it to randomly work again:
对于那些仍然遇到这种情况并且不想等待它再次随机工作的人:
I just encountered this, and cannot find any explanation other than some bug.
我刚刚遇到了这个,除了一些错误之外找不到任何解释。
I tried:
我试过:
CREATE TABLE `database`.`measurement_types` (
`TypeID` INT(2) NOT NULL AUTO_INCREMENT ,
`Name` VARCHAR(32) NOT NULL ,
`Description` VARCHAR(256) NOT NULL ,
PRIMARY KEY (`TypeID`)) ENGINE = InnoDB;
Which produced the same "Please enter valid length" error
产生了相同的“请输入有效长度”错误
Tried a few times with different length values, but kept getting the same error.
用不同的长度值尝试了几次,但一直得到相同的错误。
--SOLUTION--
- 解决方案 -
So I just created the table with a single column first, then altered it with the two other columns like so:
所以我只是先用一列创建了表,然后用另外两列修改它,如下所示:
CREATE TABLE `database`.`measurement_types` (
`TypeID` INT(2) NOT NULL AUTO_INCREMENT ,
PRIMARY KEY (`TypeID`)) ENGINE = InnoDB;
And then:
进而:
ALTER TABLE `measurement_types`
ADD `Name` VARCHAR(32) NOT NULL AFTER `TypeID`,
ADD `Description` VARCHAR(256) NOT NULL AFTER `Name`;
And that worked.
那奏效了。
I also tried to delete the table and create it with the first SQL again, and this time it worked. Seems pretty random
我还尝试删除该表并再次使用第一个 SQL 创建它,这次它起作用了。看起来很随意
回答by Aldin Philo
I have also faced the same issue and what I did was clicked on Preview SQLand copy the sql query and paste it in the SQL Run
我也遇到了同样的问题,我所做的是点击预览 SQL并复制 sql 查询并将其粘贴到 SQL 运行中
回答by WinterSoldier
You can also solve it by restarting your mysql... It worked for me.
您也可以通过重新启动 mysql 来解决它...它对我有用。
回答by Miguel Angel Romero Hernandez
I solved my “Please enter a valid length” by typing the length values for the data types that weren't of a dynamic memory allocation type. So therefore they obviously needed to know how much memory they could use for storage. Or by all means a valid length
我通过为不是动态内存分配类型的数据类型键入长度值来解决我的“请输入有效长度”。因此,他们显然需要知道他们可以使用多少内存来存储。或者无论如何都是有效的长度
回答by AlexKalopsia
I've had the same issue, seems to be a bug with VARCHAR fields. My solution was to make those fields INT, create the table, and then change them back to VARCHAR
我遇到了同样的问题,似乎是 VARCHAR 字段的错误。我的解决方案是将这些字段设为 INT,创建表,然后将它们改回 VARCHAR
回答by Vamsi
If you use Varchar
you have to give a length. Otherwise, it will not save.
如果你使用,Varchar
你必须给出一个长度。否则,它不会保存。