Press ESC to close

Manoj Bist

Unknown sql data types tinyinteger requested. any doctrine type

Unknown column type tinyinteger requested any doctorine type

Unknown column type “tinyinteger” requested. Any Doctrine type that you use has to be registered with DoctrineDBALTypesType::addType(
)

Doctorine/dbal is a PHP package, used for modifying columns programmatically without touching PHPMyAdmin or any raw queries. If you are on laravel, and modifying column, you must know, laravel is doing that for you via doctrine under the hood.

But there are limits of dataTypes not limit actually, but fewer data types are included in the core library but you can always extend the core library to add new dataType.

I came to share this article, because I faced the error Unknown column type tinyinteger requested. any doctrine type, after doing some search, got the solution. So here I am sharing that with you.

I wanted to change an int column to tinyInteger type but tinyInteger type is not defined in doctrine, only integer, big integer, and small integer are defined. So what to when facing such an error.

Native code always works anywhere anytime.

To solve this error, we will use Laravel’s DB Facade in migration and use raw query to modify a column to required dataType.

Add this to the top of your migration file

	
    	use DB;
    

Here my status column type was varchar, but now I want to change it to tinyint, so I did modify the up & down method like this.

You can see two statements in both functions, in the up method, the first is for modifying varchar to tinyint, and the second for updating column value because values should be updated to int type.

	
    	function up()
        {
            DB::statement('ALTER TABLE `users` MODIFY `status` tinyint(2) UNSIGNED NOT NULL;');
            DB::statement('UPDATE `users` SET `status` = 0 WHERE `status`;');
        }

        function down()
        {
            DB::statement('UPDATE `users` SET `status` = null WHERE `status`;');
            DB::statement('ALTER TABLE `users` MODIFY `status` varchar(20) NOT NULL;');
        }
    

Raw queries always work.

Hope this helps.

Manoj Bist

A Passionate Web Developer/Designer With over 6 years of experience in the industry, Manoj Bist is a seasoned professional who combines technical expertise with a down-to-earth demeanor. As a lover of both technology and design, he thrives on creating seamless digital experiences that captivate and inspire.

Leave a Reply

Your email address will not be published. Required fields are marked *