4

I am very new in cakephp version 3. Here I am trying to use migration plugin. I have already created a table by using below command

=> cake bake migration CreateUsers name : string 

It's worked very fine, now I am trying to add a field in here so I have written

=> cake bake migration add age:int to Users 

It's not working. How can I add this field by migration using shall command ?May you help me please ?

Alimon Karim
  • 4,354
  • 10
  • 43
  • 68
  • Even if it might be obvious for people who are used to the migrations plugin, "_doesn't work_" is _never_ a proper problem description! Please always be specific as to what exactly happens, and what you expect to happen instead! – ndm Jul 25 '15 at 18:04
  • It's create a file with a method public function change() { } But it's totally blank. – Alimon Karim Jul 25 '15 at 18:06
  • .I am actually trying to add a new field in users table. – Alimon Karim Jul 25 '15 at 18:12

1 Answers1

5

A syntax like

add column:type to table

doesn't exist, so that's why you are seeing what you're seeing. The correct syntax for adding columns is

AddColumnNameToTableName column:type

where the column name between Add and To is optional.

ie your command should look something like

bin/cake bake migration AddAgeToUsers age:int 

See

ndm
  • 59,784
  • 9
  • 71
  • 110
  • Of course, I kinda implied that people would do that, I didn't ment to promote bad practice :) Let me edit my answer... – ndm Jul 26 '15 at 13:13
  • I don't think it counts as a bad practice, rather a bad habit by doc writes (myself included) which persists - in any case thanks for correcting the answer (and I assume: future answers =)) - good work. – AD7six Jul 26 '15 at 13:25