Skip to content
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

The generator makes all integer columns as […, 'default', 'value' => null] even column set as not null #402

Open
Mirocow opened this issue Feb 26, 2019 · 1 comment
Labels

Comments

@Mirocow
Copy link

Mirocow commented Feb 26, 2019

What steps will reproduce the problem?

We have some problem with pgsql generating model rules
The generator makes all integer columns as […, 'default', 'value' => null] even column set as not null

What is the expected result?

What do you get instead?

Replace code from (https://github.com/yiisoft/yii2-gii/blob/master/src/generators/model/Generator.php#L358)

if ($driverName === 'pgsql' && $type === 'integer') {
    $rules[] = "[['" . implode("', '", $columns) . "'], 'default', 'value' => null]";
}

into

if ($driverName === 'pgsql' && $type === 'integer') {
    $defaultColumns = isset($types['required']) ? array_diff($columns, $types['required']) : $columns;
    if ($defaultColumns) {
        $rules[] = "[['" . implode("', '", $defaultColumns) . "'], 'default', 'value' => null]";
    }
}

Additional info

Q A
Yii version 2.0.16?
PHP version 7.2
Operating system Debian
@machour machour added type:bug Bug status:to be verified Needs to be reproduced and validated. labels Feb 26, 2019
@alexkart
Copy link
Contributor

alexkart commented Apr 8, 2019

I've verified this and confirm that it generates the same default rule for null and not null columns.
But, does anyone know what's the purpose of specifying a default value equals null for integers in postgresql?
I mean why is this block of code needed?

if ($driverName === 'pgsql' && $type === 'integer') {
    $rules[] = "[['" . implode("', '", $columns) . "'], 'default', 'value' => null]";
}

@samdark samdark removed the status:to be verified Needs to be reproduced and validated. label Apr 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants