Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

djay's avatar
Level 2

SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value:

I have to take some 16 digit numbers from my users as input along with other users input details. for this my migration is -

 $table->unsignedBigInteger('aadhar')->nullable();

and validation is -

'aadhar' =>'required|numeric|digits:16',

I am getting following error on submitting the form without any value - means empty field, but I have taken nullable(); in my migration

SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: '' for column 

Any suggestion please Thanks in advance

0 likes
8 replies
Snapey's avatar

does not look like a problem with the aadhar column. Also, you have said that the column is required and is 16 digits so it should not get as far as posting to the table? Are you sure its being sent to the right controller?

djay's avatar
Level 2

Hi Snapey

Yes I am sure, it is going to right controller, Actually user just register with their email and password, Now after logging in they update other details where aadhar column is also present.

Now during updation user may or may not fill all the details in one go. So I have taken nullable() in migration. So that user can submit the form without filling each and every field. And can partially update their details.

If I remove required condition from validation then also I am getting the same error.

Thanks

Snapey's avatar

Thats what I am saying - you have required in your validation rules, but it seems to have no effect.

You are also have sql complaining about a datetime format when your column is integer.

Something is not working as you are expecting.

Have a look at the mysql log to see what is being written, and find out why your validation is having no effect.

willvincent's avatar

unsignedBigInteger() isn't a thing.. that should be:

 $table->bigInteger('aadhar')->unsigned()->nullable();
Snapey's avatar

@willvincent ahh, didnt notice that. Strange that the migration did not throw an error (we assume), could it have defaulted to a datetime column?

willvincent's avatar

@Snapey very strange indeed.. perhaps the DB was created manually, separate from the migration? In which case the migration wouldn't matter at all really.

Snapey's avatar

Nope, unsignedBigInteger works!

I just tried it on a migration and I ended up with a big integer column with the unsigned flag set!

Migration: $table->unsignedBigInteger('aadhar')->nullable();

CREATE TABLE `test` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `aadhar` bigint(20) unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
Aron_Arjun's avatar

SQLSTATE[HY000]: General error: 1005 Can't create table account.#sql-200c_2d8 (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alt er table jobs add constraint jobs_service_id_foreign foreign key (service_id) references services (id) on delete cascade).... i had just tried the above code but the above error was given

Please or to participate in this conversation.