We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

MySQL PDO dialect generates wrong DEFAULT clause from Migrations array

Hello everyone,

recently I've noticed that the DEFAULT clauses give me error with the following column config:

new Column(
    'label',
    [
        'type' => Column::TYPE_VARCHAR,
        'size' => 128,
        'notNull' => true,
        'default' => '',
        'after' => 'id',
    ]
)

The reason is that createTable() method in Phalcon\Db\Dialect\Mysql generates DEFAULT clause with default value wrapped into double quotes(") instead of quotation marks (');

It happens due to this code.

Can someone please confirm this behaviour is correct or whether it's me doing it wrong?

edited Aug '16

Is equals.

https://dev.mysql.com/doc/refman/5.7/en/string-literals.html

but, using double quotes for string delimiters isn't standard SQL, so it's good practice to use single quotes.

edited Aug '16

Error because you define:

NOT NULL and DEFAULT '' <- mode strict == NULL

Try, remove default = ''

Thanks for your reply.

Yup, removing DEFAULT clause works, but what should I do if I need an empty string as default value? And, if using single quotes is a good practice shouldn't PDO adapter insert them instead?