2016-01-22 42 views
3

我正在使用cakephp 3 migrations插件來設計數據庫。我想添加一個status字段tinyint與限制爲1到一個字段,我試過以下,但沒有加起來。如何使用遷移插件將tinyint添加到cakephp 3中的databse字段?

嘗試1(失敗)

$table->addColumn('status', 'smallinteger', [ 
     'default' => 0, 
     'limit' => 1, 
     'null' => false, 
]); 

嘗試2(失敗)

$table->addColumn('status', 'tinyint', [ 
     'default' => 0, 
     'limit' => 1, 
     'null' => false, 
]); 

我找不到相同的任何文件,可能是它的存在,我丟失東西Docs Link

回答

5

添加布爾字段類型增加了TINYINT塔1個

$table 
     ->addColumn('status', 'boolean', [ 
       'default' => false, 
       'null' => false, 
      ]); 
+0

謝謝,我不認爲這樣cakephp以tinyint 1作爲布爾值 –

1

遷移插件使用Phinx庫exe切割這些更新。添加TINYINT列應當與MysqlAdapter::INT_TINY常數如下進行:

use Phinx\Db\Adapter\MysqlAdapter; 
... 
$table->addColumn('status', 'tinyint', [ 
    'default' => 0, 
    'limit' => MysqlAdapter::INT_TINY, // 255 
    'null' => false, 
]); 

來源:長度的Phinx Mysql Tinyint

+1

PHP致命錯誤:類'MysqlAdapter'找不到/var/www/html/cake3plugin/config/Migrations/20160122144154_CreateProducts.php on line 35 –

+0

N nem解決方案以任何方式爲我工作 –

+1

你必須在頂部添加要使用的類。 '使用Phinx \ Db \ Adapter \ MysqlAdapter;'。 如果N nem的解決方案正常工作,那很好。 – Awemo

相關問題