-
-
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
MySQL: Fix primary key alteration when adding new columns #2696
Conversation
A feedback from someone of the doctrine/dbal team would be great. |
@@ -708,6 +709,10 @@ private function getPreAlterTableAlterPrimaryKeySQL(TableDiff $diff, Index $inde | |||
|
|||
// Dropping primary keys requires to unset autoincrement attribute on the particular column first. | |||
foreach ($index->getColumns() as $columnName) { | |||
if(isset($diff->addedColumns[$columnName]) && $diff->addedColumns[$columnName] instanceof Column) { | |||
continue; | |||
} |
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.
I think using the following check is more convenient and safer concerning the following getColumn()
call:
if (! $diff->fromTable->hasColumn($columnName)) {
continue;
}
4e57458
to
55557d0
Compare
@deeky666 Done :) PS: The fix could also be added to branch 2.5. |
55557d0
to
3717c49
Compare
@@ -708,6 +708,10 @@ private function getPreAlterTableAlterPrimaryKeySQL(TableDiff $diff, Index $inde | |||
|
|||
// Dropping primary keys requires to unset autoincrement attribute on the particular column first. | |||
foreach ($index->getColumns() as $columnName) { | |||
if(!$diff->fromTable->hasColumn($columnName)) { |
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.
sorry to nitpick but we use the following code style if (! $diff
can you please adjust that? afterwards I'll merge.
3717c49
to
fb018c0
Compare
primary key on MySQL platform.
fb018c0
to
fa2a12e
Compare
@drieschel thanks! Backported to |
Trying to get a column in a table which is not added yet, will result in throwing a SchemaException. Also altering not yet added columns does not make sense.