Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

phpMyAdmin - "Please enter a valid length"

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

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.

like image 658
Nicholas Hassan Avatar asked Nov 20 '16 19:11

Nicholas Hassan


People also ask

What is valid length in phpmyadmin?

CHAR = Characters – used to store character string value of fixed length, the maximum number is of characters is 255. VARCHAR = Variable Length Characters – used to store variable length alphanumeric data and can store up to 65,535 characters.

What does varchar 30 mean?

The CHAR and VARCHAR types are declared with a length that indicates the maximum number of characters you want to store. For example, CHAR(30) can hold up to 30 characters. The length of a CHAR column is fixed to the length that you declare when you create the table. The length can be any value from 0 to 255.

What is the maximum length of a column in MySQL?

The following table describes the maximum length for each type of identifier. Aliases for column names in CREATE VIEW statements are checked against the maximum column length of 64 characters (not the maximum alias length of 256 characters).

How do I find the length of a column in MySQL?

LENGTH() function MySQL LENGTH() returns the length of a given string.


2 Answers

I have also faced the same issue and what I did was clicked on Preview SQL and copy the sql query and paste it in the SQL Run

like image 182
Aldin Philo Avatar answered Oct 19 '22 22:10

Aldin Philo


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

like image 11
Pjottur Avatar answered Oct 19 '22 20:10

Pjottur