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

MySQL default blank string displays as two single quotes in form field. #20275

Open
hvprvtr opened this issue Nov 6, 2024 · 0 comments
Open

Comments

@hvprvtr
Copy link

hvprvtr commented Nov 6, 2024

Hello. I got table in MySQL with default blank string value. In SQL it looks like:

`key` TINYTEXT NOT NULL DEFAULT '',

In the model i set rule with blank string as default value:

[['key'], 'default', 'value' => ''],

And i try to do simple form with it

    <?= $form->field($model, 'key')->textarea(['rows' => 6]) ?>

In the form i see textarea with two single quotes as default value.

two single quotes

All fields with default blank string value got this bug.

My connection params:

return [
    'class' => 'yii\db\Connection',
    'dsn' => 'mysql:host=localhost;dbname=xxx',
    'username' => 'xxx',
    'password' => 'xxx',
    'charset' => 'utf8',
];

How can i fix it?

I try to dump $model->key before form display and got this value - two single quotes.
I seen ActiveRecord::loadDefaultValues and tried dump there - got this bug there.

bad default value

I found only one decision - set no default value and set blank string in the model code. But this is no right because i got other soft works with this db and it use default values.

Yii v2, PHP v8.3.13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant