1

I am new to cakephp3.refer http://book.cakephp.org/3.0/en/migrations.html and try to create database using terminal.for example:

bin/cake bake migration CreateProducts name:string description:text created modified

this command create file and when use below command it creates database table in phpmyadmin:

bin/cake migrations migrate

But I want to update table with add one column in it..so when I try to update database table it create another migration file ..each time when I want to update database table..these seems weired..because I want to update single table.. Is there any way ,so I am updating database table with same function each time through migration??

Alimon Karim
  • 4,354
  • 10
  • 43
  • 68
Krunal Dave
  • 272
  • 6
  • 16

1 Answers1

2

When you are using migration,see in database there has a table name phinxlog. In this table there has a field name called version. When you will give command

bin/cake migrations migrate

Then this table will be update. Now see the version field, here some number like 20150911090111. This number actually added with your migration file, am I right ?

If this number already accessed in your phinxlog table, this file will never access again. That means after your command

 bin/cake migrations migrate

That command will not apply on this file which already accessed in pinixlog table.

So don't be afraid if another migration file has been created. For add new column please see

How to add a field in database table by cakephp migration?

Yes, It's also possible to add new column in your old migration file, just add manually like

->addColumn('field_name', 'types', [
                'default' => null,
                'limit' => 11,
                'null' => false,
 ])

Then rename the file name. Then give the migration migrate again.I hope it will work now.

Community
  • 1
  • 1
Alimon Karim
  • 4,354
  • 10
  • 43
  • 68
  • ok..now my doubt clear..thanks for help..IS it possible to migrate all data along with column name using:bin/cake bake migration_snapshot Initial ?? – Krunal Dave Oct 09 '15 at 09:36
  • Yes it's possible. After add new column if all column has been added then apply bin/cake bake migration_snapshot Initial command again. Make sure new Initial migration file position on top. You can do it by rename file. I think you know about the meaning of 20150911090111 this digits meaning. – Alimon Karim Oct 09 '15 at 09:41
  • bin/cake bake migration_snapshot Initial command migrate only database tables and its columns ,but i want to also migrate all tables rows/Data ...so is it possible?? – Krunal Dave Oct 09 '15 at 09:50
  • ok I understand, No it's not possible but you can make your own dummy data insert code. see this link http://stackoverflow.com/questions/30712896/cakephp-how-to-use-migration-to-insert-records You have to add it manually. – Alimon Karim Oct 09 '15 at 09:52