diff --git a/src/Illuminate/Database/Schema/Grammars/ChangeColumn.php b/src/Illuminate/Database/Schema/Grammars/ChangeColumn.php index aa50bfff67e6..70ec66652eb9 100644 --- a/src/Illuminate/Database/Schema/Grammars/ChangeColumn.php +++ b/src/Illuminate/Database/Schema/Grammars/ChangeColumn.php @@ -125,6 +125,10 @@ protected static function getDoctrineColumnChangeOptions(Fluent $fluent) $options['length'] = static::calculateDoctrineTextLength($fluent['type']); } + if ($fluent['type'] === 'char') { + $options['fixed'] = true; + } + if (static::doesntNeedCharacterOptions($fluent['type'])) { $options['customSchemaOptions'] = [ 'collation' => '', @@ -151,6 +155,7 @@ protected static function getDoctrineColumnType($type) 'mediumtext', 'longtext' => 'text', 'binary' => 'blob', 'uuid' => 'guid', + 'char' => 'string', default => $type, }); } diff --git a/tests/Database/DatabaseSchemaBlueprintIntegrationTest.php b/tests/Database/DatabaseSchemaBlueprintIntegrationTest.php index b64472332c07..0e990ecd848f 100644 --- a/tests/Database/DatabaseSchemaBlueprintIntegrationTest.php +++ b/tests/Database/DatabaseSchemaBlueprintIntegrationTest.php @@ -126,6 +126,29 @@ public function testChangingColumnWithCollationWorks() $this->assertEquals($expected2, $queries2); } + public function testChangingCharColumnsWork() + { + $this->db->connection()->getSchemaBuilder()->create('users', function ($table) { + $table->string('name'); + }); + + $blueprint = new Blueprint('users', function ($table) { + $table->char('name', 50)->change(); + }); + + $queries = $blueprint->toSql($this->db->connection(), new SQLiteGrammar); + + $expected = [ + 'CREATE TEMPORARY TABLE __temp__users AS SELECT name FROM users', + 'DROP TABLE users', + 'CREATE TABLE users (name CHAR(50) NOT NULL COLLATE BINARY)', + 'INSERT INTO users (name) SELECT name FROM __temp__users', + 'DROP TABLE __temp__users', + ]; + + $this->assertEquals($expected, $queries); + } + public function testRenameIndexWorks() { $this->db->connection()->getSchemaBuilder()->create('users', function ($table) {