-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Fix mysql QueryBuilder boolean type #9324
Conversation
What is the problem currently? |
The problem is that yii type boolean type is considered mysql bit (1), and in QueryBuilder it is incorrect. When we create a migration using Schema :: TYPE_BOOLEAN, database type we get Schema :: TYPE_SMALLINT, and the model of type integer. Sorry that just has not. I do not have time to issue. |
What do you mean by "in QueryBuilder it is incorrect"? |
public $typeMap = [ |
Why |
@samdark its not wrong to use The problem I think would be if all SQL engines support it to avoid generating problems when migrating from one db engine to another |
the mysql synonym for boolean is tinyint(1):
https://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.html |
Why the alias MySQL? yii type boolean considers the type bit (1). |
it considers bit(1) and tinyint(1), what is the problem? |
The problem is that yii in accordance with the Code file if ($column->size === 1 && $ type === 'bit') {
$column->type = 'boolean';
} At this time, Thus It does not matter what's in the mysql alias type |
this line should cover the tinyint(1) case too then. https://github.com/yiisoft/yii2/blob/master/framework/db/mysql/Schema.php#L160 I thought it was already doing this... |
@cebe So can not be done |
closing this in favor of #9339 |
The problem is that yii type boolean type is considered mysql bit (1), and in QueryBuilder it is incorrect. When we create a migration using Schema :: TYPE_BOOLEAN, database type we get Schema :: TYPE_SMALLINT, and the model of type integer.
/framework/db/mysql/Schema.php
if ($column->size === 1 && $type === 'bit') {
$column->type = 'boolean';
}
/framework/db/mysql/QueryBuilder.php
public $typeMap = [
...
Schema::TYPE_BOOLEAN => 'tinyint(1)',
...
];