yii2: Silently fail when comments not supported in migrations.
What steps will reproduce the problem?
- Use SQLite as a backend.
- Create a table with a column that has a comment.
What is the expected result?
Create the column as specified.
What do you get instead?
An error: Exception 'yii\base\NotSupportedException' with message 'yii\db\sqlite\QueryBuilder::addCommentOnColumn is not supported by SQLite.'
I’m not 100% sure if failing silently is the best solution / should be the default behavior. It would be nice to have something that indicates this. For example adding a second parameter:
$this->integer()->comment('Comment is nice but not required', true);
Where the true
indicates that it can fail silently in case comments are not supported by the backend.
About this issue
- Original URL
- State: open
- Created 8 years ago
- Comments: 39 (38 by maintainers)
@h311ion Because we don’t want to change the current behavior, in case anyone depends on having the comments saved we would not want to silently “not save” them.
Adding
optionalComment
is basically adding database-specific behavior for SQLite; this allows users of the Yii framework to still write database-independent code (which is the point of the database abstraction layer).We can reverse this solution and create param like
notRequiredDbFeatures
which will be empty by default and you need insertcomments
into it to ignore unsupported comments exceptions.Or something more sophisticated:
dbRequirements
override settings fromdefaultDbRequirements
- you can createapp\components\Migration
and set this requirements in application level, then you don’t need repeat this on everycomment()
call.Because then I do not know what is not supported; it could be the data type, a default value or whatever other configuration I’m using. The point is that comments typically are for improved maintainability but are not strictly required for running your code.