Skip to content

[9.x] Support modifying a char column type#41320

Merged
taylorotwell merged 1 commit intolaravel:9.xfrom
hafezdivandari:9.x
Mar 3, 2022
Merged

[9.x] Support modifying a char column type#41320
taylorotwell merged 1 commit intolaravel:9.xfrom
hafezdivandari:9.x

Conversation

@hafezdivandari
Copy link
Copy Markdown
Contributor

@hafezdivandari hafezdivandari commented Mar 3, 2022

This PR provides support for modifying a char column type.

Schema::table('users', function (Blueprint $table) {
    $table->char('name', 50)->nullable()->change();
});

Before this PR, modifying a char column led to an error:

Unknown column type \"char\" requested. Any Doctrine type that you use has to be registered with \\Doctrine\\DBAL\\Types\\Type::addType(). You can get a list of all the known types with \\Doctrine\\DBAL\\Types\\Type::getTypesMap(). If this error occurs during database introspection then you might have forgotten to register all database types for a Doctrine Type. Use AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement Type#getMappedDatabaseTypes(). If the type name is empty you might have a problem with the cache or forgot some mapping information

But doctrine/dbal package actually supports modifying char column types as StringType::class by setting fixed option to true.

So this PR, maps Laravel char to its Doctrine equivalent string type and set fixed option to true that finally gets the SQL snippet to declare a CHAR column.

@taylorotwell
Copy link
Copy Markdown
Member

Can you describe how you determined these changes were needed and what the problem was before this fix?

@taylorotwell
Copy link
Copy Markdown
Member

Please mark as ready once you have done so.

@taylorotwell taylorotwell marked this pull request as draft March 3, 2022 14:51
@hafezdivandari
Copy link
Copy Markdown
Contributor Author

@taylorotwell sure, I updated my comment above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants