-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Ensure the default is declared in the same statement for new columns #4447
Ensure the default is declared in the same statement for new columns #4447
Conversation
4f548e8
to
08ba403
Compare
Thank you for the patch, @duncan3dc. In addition to the unit test, it would be good to have an integration test that confirms that the fixed SQL also works and produces the expected results. See the testing guidelines for more details. |
a27f64c
to
2ea06d1
Compare
Of course, I've had a go at that in 2ea06d1 it fails against the 2.12.x branch and passes with this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Please squash into one commit since the code change and both tests belong together.
@@ -484,12 +484,15 @@ public function getAlterTableSQL(TableDiff $diff) | |||
} | |||
|
|||
$columnDef = $column->toArray(); | |||
$queryParts[] = 'ADD ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnDef); | |||
|
|||
$addColumnSql = 'ADD ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnDef); | |||
if (isset($columnDef['default'])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is out of the scope of this issue but it looks like this code incorrectly handles the DEFAULT NULL
case.
2ea06d1
to
caf5c0f
Compare
Thanks, @duncan3dc! |
Summary
When adding columns to tables that already contain data, SQL Server requires that the default constraint is declared in the same statement, Doctrine currently generates a separate
ADD CONSTRAINT
statement, which means the add column statement errors with something like: