bizley / yii2-migration

Yii 2 Migration Creator And Updater
Apache License 2.0
291 stars 36 forks source link

[Bug] Setting default values using expressions fails #177

Closed khalid-eyez closed 2 years ago

khalid-eyez commented 2 years ago

Describe the bug setting default values using expressions fails in version 4.3.1 because expressions are resolved to something that is not accepted in MySQL, I am using 10.4.24-MariaDB.

Affected versions v4.3.1

database engine: Innodb (10.4.24-MariaDB)

dcc bug1

bizley commented 2 years ago

version 4.3.1 of this extension has already been released but i cannot get it through composer

How do you have it set in the composer.json?

And as for the rest: Please provide me with the SQL statement to create the table you made the migration of.

khalid-eyez commented 2 years ago

okay i have verified the version is 4.3.1 even if in the file migrationController it is still 4.3.0

khalid-eyez commented 2 years ago

CREATE TABLE announcement ( annID int(11) NOT NULL AUTO_INCREMENT, instructorID int(11) DEFAULT NULL, course_code varchar(7) DEFAULT NULL, content varchar(500) NOT NULL, ann_date date NOT NULL DEFAULT current_timestamp(), ann_time time NOT NULL DEFAULT current_timestamp(),

khalid-eyez commented 2 years ago

that is how it was created...you can see how different it is from the output of the migration command

bizley commented 2 years ago

This is happening because of this line in Yii 2 core. The expression current_timestamp() or current_timestamp is recognized only for columns of type datetime or timestamp while you are providing date and time here. But since it works obviously (on MariaDB at least, MySQL is not allowing functions as defaults) I need to see if the update in the Yii 2 needs to be done.

bizley commented 2 years ago

If the update happens I will link it here but since this depends on the Yii core I cannot fix it and it won't work for previous versions of Yii anyway.

khalid-eyez commented 2 years ago

This is happening because of this line in Yii 2 core. The expression current_timestamp() or current_timestamp is recognized only for columns of type datetime or timestamp while you are providing date and time here. But since it works obviously (on MariaDB at least, MySQL is not allowing functions as defaults) I need to see if the update in the Yii 2 needs to be done.

but YII2 have added another function which i thought would work properly in this case, defaultExpression(). since expressions like current_timestamp or current_timestamp() work well in a database for date columns, i think it should be handled well to work with migrations for the same column types.

bizley commented 2 years ago

The method you are talking about is used to create an sql statement but here I'm extracting this data from the table and Yii is not aware that it is an expression because of what I showed you so it says it must be a simple text.

khalid-eyez commented 2 years ago

Okay that's a YII2 fix then

bizley commented 2 years ago

My fix is already merged, waiting for the release.

bizley commented 1 year ago

Yii 2.0.47 has been released.