【问题标题】:How to set visible length for type tinyint,smallint while alter column using phinx migration in cakephp3?如何在 cakephp3 中使用 phinx 迁移更改列时为 tinyint、smallint 类型设置可见长度?
【发布时间】:2018-10-20 15:10:47
【问题描述】:

我尝试使用以下代码将字段“exp”迁移到数据类型 tinyint(2),我想使用数据类型 tinyint 将可见长度设为 2。

$table->changeColumn('exp', 'integer', [
            'limit' =>  MysqlAdapter::INT_TINY,
//is there any option to set visible length 2, by default it is taking length 4
//I tried 'length'=>4, but it overrides 'limit' and datatype becomes int(4)
            'null' => false,
            'default' => '0'
        ]);

I want alter the column with this type

【问题讨论】:

  • 请不要投反对票,我浏览了 phinx 提供的文档,但没有找到此查询的任何答案。
  • 注意:没有ZEROFILLTINYINT(2)TYNYINT(4)之间没有区别。
  • 我明白你指出@PaulSpiegel 你是对的,但是由于新表结构中没有提供 ZEROFILL 我没有提到它。我检查了 phinx 文档,也没有 ZEROFILL 选项.

标签: mysql database-migration cakephp-3.x phinx


【解决方案1】:

尝试普通查询:

$this->execute('ALTER TABLE `table_name` ADD COLUMN `exp` TINYINT(2) NOT NULL DEFAULT 0');

【讨论】:

    猜你喜欢
    • 2016-09-13
    • 1970-01-01
    • 1970-01-01
    • 2016-06-01
    • 2017-07-28
    • 2021-12-04
    • 2015-02-07
    • 1970-01-01
    • 2016-09-28
    相关资源
    最近更新 更多