Struggled by Migration Err and Solved
CakePHP Migratation Error
want
I want to make database table in cake php console, so I searched migration command, but it does not work
Err
Foos-MBP:cms kaede$ bin/cake migrations migrate using migration paths - /Users/kaede/code/cake3/cms/config/Migrations using seed paths - /Users/kaede/code/cake3/cms/config/Seeds using environment default using adapter mysql using database cake_cms == 20190814163826 CreateTests: migrating PDOException: SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'id' in /Users/kaede/code/cake3/cms/vendor/robmorgan/phinx/src/ Phinx/Db/Adapter/PdoAdapter.php:167
It said deplicated
, but Even the table was NOT created...
<?php use Migrations\AbstractMigration; class CreateProducts extends AbstractMigration { /** * Change Method. * * More information on this method is available here: * http://docs.phinx.org/en/latest/migrations.html#the-change-method * @return void */ public function change() { $table = $this->table('products'); $table->addColumn('name', 'string', [ 'default' => null, 'limit' => 255, 'null' => false, ]); $table->addColumn('description', 'text', [ 'default' => null, 'null' => false, ]); $table->addColumn('created', 'datetime', [ 'default' => null, 'null' => false, ]); $table->addColumn('modified', 'datetime', [ 'default' => null, 'null' => false, ]); $table->create(); } }
solved
one of the migration file has a id
column,
that is deplicated the default generated auto increment
id key. So I deleted the migration file, then all worked.
I confirmed in MySQL.
Done. Never make a column named id!!