Skip to content

[6.x] Change MySql nullable modifier to allow generated columns to be not null #31452

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

Merged
merged 2 commits into from
Feb 13, 2020
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