开发者

How to get doctrine to generate sql with BIGINT type?

开发者 https://www.devze.com 2023-03-06 01:15 出处:网络
In my schema I have a number of field that need to be BIGINT. I u开发者_StackOverflowse the following command from Symfony

In my schema I have a number of field that need to be BIGINT. I u开发者_StackOverflowse the following command from Symfony

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?


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.


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)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消