0
votes

SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: 'Walking' for column 'excercise_type' at row 1

 public function up()
{
    Schema::table('diabetic_records', function (Blueprint $table) {
        $table->unsignedInteger('user_id')->nullable()->after('id');
        $table->decimal('glucose_level',5,2)->nullable()->after('user_id');
        $table->string('glucose_level_time')->nullable()->after('glucose_level');
        $table->string('food_name')->nullable()->after('glucose_level_time');
        $table->integer('food_amount')->nullable()->after('food_name');
        $table->string('treatment')->nullable()->after('food_amount');
        $table->string('medication_name')->nullable()->after('treatment');
        $table->decimal('medication_dose',6,2)->nullable()->after('medication_name');
        $table->string('medication_time')->nullable()->after('medication_dose');
        $table->integer('excercise_type')->nullable()->after('medication_time');
        $table->integer('excercise_duration')->nullable()->after('excercise_type');
    });
}
2
The errors are correct. 1366 is not a valid date/time, and Walking is not an integer. You're either trying to insert incorrect data, or you're trying to change a column type for a table that already contains data that doesn't match the new column type. - rickdenhaan

2 Answers

0
votes

The data type of excercise_type in database must have been set to DATETIME. Change it to int(11). And the value must be a integer, not string i.e. Walking. That might solve your problem.

0
votes

I just found the solution of this problem by asking this problem to my elder brother. first of all my data type of exercise is int and i am putting characters(string) in it.

$table->integer('excercise_type')->nullable()->after('medication_time');

view:

<select class="custom-select d-block w-100" name="excercise_type" id="excercise_type" required>
              <option selected="selected" >Walking</option>
              <option >Running</option>
              <option >Cycling</option>
              </select>

before error resolving the code look like this which i typed

now lets start resolving part of this error

1)First of all give values like 1,2,3 to your options under select tag in your view .

<select class="custom-select d-block w-100" name="excercise_type" id="excercise_type" required>
              <option selected="selected" value="1">Walking</option>
              <option value="2">Running</option>
              <option value="3">Cycling</option>
              </select>

2) just go to your config folder and create a file with the name of constant.php .

3) now return an array and write the name of your input field and assign them values of your option field which your write in your view side like this .

<?php
return[
 'EXERCISE_TYPE_WALKING' => '1',
 'EXERCISE_TYPE_RUNNING' => '2',
' EXERCISE_TYPE_CYCLING' => '3',
];

?>

i hope you will get help by this.