MySQLに直接アクセスして、テーブルを作成することはできます。(以下テーブル作成クエリ)
sql
1 CREATE TABLE `comment_table` ( 2 `comment_table_id` int(11) unsigned NOT NULL AUTO_INCREMENT , 3 `post_id` int(11) NOT NULL , 4 `user_id` int(11) NOT NULL , 5 `id` int(11) NOT NULL , 6 `text` text NOT NULL , 7 `img` text , 8 `create_at` datetime NOT NULL, 9 PRIMARY KEY (`colony_comment_table_id`) 10 ) ENGINE=InnoDB AUTO_INCREMENT=36 DEFAULT CHARSET=utf8;
しかし、CakePHP3のコード上で上と同じようなコードを再現することができません。
公式ドキュメントを読んで書いてみたのですが、やはり動作しないようです。
php
1 class MapsController extends AppController { 2 public function createColony(){ 3 $createTable = $this->table('comment'); 4 $createTable 5 ->addPrimaryKey('comment_table_id','int',[ 6 'limit'=>11, 7 'unsigned'=>true, 8 'NOT NULL'=>true, 9 'AUTO_INCREMENT'=>true 10 ]) 11 ->addColumn('post_id','int',[ 12 'limit'=>11, 13 'NOT NULL'=>true, 14 ]) 15 ->addColumn('user_id','int',[ 16 'limit'=>11, 17 'NOT NULL'=>true 18 ]) 19 ->addColumn('id','int',[ 20 'limit'=>11, 21 'NOT NULL'=>true 22 ]) 23 ->addColumn('text','text',[ 24 'NOT NULL'=>true 25 ]) 26 ->addColumn('img','text') 27 ->addColumn('create_at','datetime',[ 28 'NOT NULL' 29 'limit'=>11, 30 'NOT NULL'=>true, 31 ]) 32 ->addColumn('user_id','int',[ 33 'limit'=>11, 34 'NOT NULL'=>true 35 ]) 36 ->addColumn('colony_id','int',[ 37 'limit'=>11, 38 'NOT NULL'=>true 39 ]) 40 ->addColumn('text','text',[ 41 'NOT NULL'=>true 42 ]) 43 ->addColumn('img','text') 44 ->addColumn('create_at','datetime',[ 45 'NOT NULL' 46 ]) 47 ->create(); 48 } 49 } 50
なにかありましたら、随時補足いたします。
よろしくお願いします。

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。