How to get doctrine to generate sql with BIGINT ty

2019-07-03 19:02发布

In my schema I have a number of field that need to be BIGINT. I use symfony's

symfony doctrine:build-sql

to generate my database.

The fields always come out as type int.

I have tried the following types in the schema:

int

{type: integer, notnull: true}

{type: integer(5), notnull: true}

{type: bigint, notnull: true}

None of them seem to work (I always rebuild the model before building the SQL).

What type should i put in the schema.yml?

3条回答
Ridiculous、
2楼-- · 2019-07-03 19:15

yes, integer(5) should do the work.

You can check other schema data types in The symfony and Doctrine book, but have in mind that it's version 1.2 and it's not maintained anymore.

Best regards.

查看更多
走好不送
3楼-- · 2019-07-03 19:18

With Symfony 2.x (e.g. Doctrine 2.4.1) and PHP annotations on Entities, using @ORM\Column(name="id", type="bigint") results in a MySQL bigint(20).

NB: OP tagged this question with symfony1 & doctrine1, for which this solution will not work.

查看更多
我欲成王,谁敢阻挡
4楼-- · 2019-07-03 19:30

It depends on your RDBMS, but if you use MySQL, you can read lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/DataDict/Mysql.php

    case 'integer':
    case 'int':
            if ( ! empty($field['length'])) {
                $length = $field['length'];
                if ($length <= 1) {
                    return 'TINYINT';
                } elseif ($length == 2) {
                    return 'SMALLINT';
                } elseif ($length == 3) {
                    return 'MEDIUMINT';
                } elseif ($length == 4) {
                    return 'INT';
                } elseif ($length > 4) {
                    return 'BIGINT';
                }
            }
            return 'INT';

so your second attempt should have worked... or do you use another RDBMS? You should set a breakpoint at this line of code and do step-by-step debugging, this is strange. Also, check the content of your Mysql.php file to see if you have the same thing as me (I use the doctrine shipped with sf 1.4.11)

查看更多
登录 后发表回答