Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,10 @@ protected function modifyNullable(Blueprint $blueprint, Fluent $column)
if (is_null($column->virtualAs) && is_null($column->storedAs)) {
return $column->nullable ? ' null' : ' not null';
}

if ($column->nullable === false) {
return ' not null';
}
}

/**
Expand Down
9 changes: 9 additions & 0 deletions tests/Database/DatabaseMySqlSchemaGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,15 @@ public function testAddingGeneratedColumn()

$this->assertCount(1, $statements);
$this->assertSame('alter table `products` add `price` int not null, add `discounted_virtual` int as (price - 5), add `discounted_stored` int as (price - 5) stored', $statements[0]);

$blueprint = new Blueprint('products');
$blueprint->integer('price');
$blueprint->integer('discounted_virtual')->virtualAs('price - 5')->nullable(false);
$blueprint->integer('discounted_stored')->storedAs('price - 5')->nullable(false);
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());

$this->assertCount(1, $statements);
$this->assertSame('alter table `products` add `price` int not null, add `discounted_virtual` int as (price - 5) not null, add `discounted_stored` int as (price - 5) stored not null', $statements[0]);
}

public function testAddingGeneratedColumnWithCharset()
Expand Down