-
Notifications
You must be signed in to change notification settings - Fork 11.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Unknown column type "mediumInteger" requested" error after downgrading doctrine/dbal to 2.* #36509
Comments
What exact DBAL version are you running? |
@driesvints |
And which Laravel version? (please fill out the issue template correctly next time) |
@driesvints Sorry, now I noticed I actually provided the composer requirement itself. Installed |
Please update to the latest version of the framework that supports this DBAL version. Thanks |
I know it's an old issue, but I ran into it as well. I didn't want to resort to workarounds, so I found the fix for the problem. This way, there's no need to touch any packages. You can simply declare the Requirements
SolutionCreate the class corresponding to our type based on the following template: App\Database\Types\MediumInteger.php<?php
namespace App\Database\Types;
use Doctrine\DBAL\Types\IntegerType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
/**
* Custom type for medium integer.
*/
class MediumInteger extends IntegerType
{
// Important: leave it as is, Laravel Schema will look for it by this name
const NAME = 'mediuminteger';
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
// getMediumIntTypeDeclarationSQL() not defined
// return $platform->getMediumIntTypeDeclarationSQL($fieldDeclaration);
// _getCommonIntegerTypeDeclarationSQL() protected, so cant call it
// return 'MEDIUMINT' . $platform->_getCommonIntegerTypeDeclarationSQL($fieldDeclaration);
// call the generation of Integer type, prepend the missing word MEDIUM
return 'MEDIUM' . $platform->getIntegerTypeDeclarationSQL($fieldDeclaration);
}
public function convertToPHPValue($value, AbstractPlatform $platform)
{
// This is executed when the value is read from the database. Make your conversions here, optionally using the $platform.
return $value === null ? null : (int) $value;
}
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
// This is executed when the value is written to the database. Make your conversions here, optionally using the $platform.
return $value === null ? null : (int) $value;
}
public function getName()
{
return self::NAME;
}
} The Laravel framework provides the ability to declare custom types once we've created the corresponding classes for them. To achieve this, we need to follow the following pattern in the use App\Database\Types\MediumInteger;
'dbal' => [
'types' => [
MediumInteger::NAME => MediumInteger::class,
],
], More information
|
|
Description:
I was having an issue with migrations when trying to change column types. It was the
Class 'Doctrine\DBAL\Driver\PDOMySql\Driver' not found
error after trying to migrate. I managed to solve this specific error by downgrading doctrine/dbal to 2.*.But now I get this error when trying to migrate to change column types:
This is the migration code:
Steps To Reproduce:
theoretically:
mediumInteger
php artisan migrate
There might be the
Driver not found error
, so follow to this issue and downgrade doctrine/dbal to 2.*The text was updated successfully, but these errors were encountered: