0

I am modifying a WebApp created on Wampserver. I want to add some options like a dropdown list named 'District' on the page CustomerData/Create.

After adding the code on fields.yaml :

    district:
        label: 'District'
        options:
            Ab: Aberdeen
            Ad: Admiralty
            Ap: Ap Lei Chau
            Ca: Causeway Bay
            Ce: Central
            H: Happy Valley
            K: Kowloon
            M: Mid Levels
            N: North Point
            Pe: Peak
            Po: Pok Fu Lam
            Q: Quarry Bay
            Sa: Sai Ying Pun
            Sh: Sheung Wan
            Ta: Taikoo Shing
            Ti: Tin Hau
            Wa: Wan Chai
            Wo: Wong Chuk Hang
            NT: NT
        span: left
        required: 1
        type: dropdown
        tab: 'Contact Information'

On MySQL Workbench, I added 'District'as ENUM('Kowloon','Central','North Point','Quarry Bay','Taikoo Shing','Tin Hau','Wan Chai','Happy Valley','Sai Ying Pun','Mid Levels','Sheung wan','Pok Fu Lam','Admiralty','Kennedy Town','Ap Lei Chau','Peak','Wong Chuk Hang','NT','Causeway Bay').

Nevertheless, I have the following error :

SQLSTATE[010000]:Warning:125 Data Truncated for column 'District' at row 1 (SQL: insert into ..... on line 664 of C:\wamp64...\Database\Connection.php)

Here is the code of Connection.php at line 664 :

protected function runQueryCallback($query, $bindings, Closure $callback)
{
    // To execute the statement, we'll simply call the callback, which will actually
    // run the SQL against the PDO connection. Then we can calculate the time it
    // took to execute and log the query SQL, bindings and time in our memory.
    try {
        $result = $callback($query, $bindings);
    }

    // If an exception occurs when attempting to run a query, we'll format the error
    // message to include the bindings with SQL, which will make this exception a
    // lot more helpful to the developer instead of just the database's errors.
    catch (Exception $e) {
        throw new QueryException(
            $query, $this->prepareBindings($bindings), $e
        );
    }

    return $result;
}

How to fix this error?

Udhav Sarvaiya
  • 9,380
  • 13
  • 53
  • 64
Antoine4
  • 21
  • 1
  • 5

1 Answers1

0

You'll get the Data truncated for column... error when inserting an ENUM value that isn't specifically enumerated (as in, it isn't one of the specific ENUM options you inserted when creating the column).

Your options: in your fields.yaml file follow a key => label format; this means the value preceding the colon should be the actual enum value (i.e. Kowloon or Central) and then what follows is the actual label used for the drop down menu.

G1N
  • 154
  • 3
  • 13