CakePHP 迁移 CreateTable 失败
CakePHP Migration CreateTable Fail
我要学习cake中的bake迁移命令php,
所以我创建了一个名为 product
的 table
bin/cake bake migration CreateProduct
和 bin/cake migration migrate
为了再次将其作为训练,我将 table 删除了 drop table product
并删除了迁移 php 文件,并且
bin/cake bake migration CreateTableName
name:string description:text created modified
成功,迁移文件已成功制作
<?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('des', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
]);
$table->addColumn('text', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
]);
$table->addColumn('created', 'datetime', [
'default' => null,
'null' => false,
]);
$table->addColumn('modified', 'datetime', [
'default' => null,
'null' => false,
]);
$table->create();
}
}
并且还制作了迁移文件
<?php
use Migrations\AbstractMigration;
class Migrate 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 找不到!
如何创建一个 table 其名称与删除的 table 相同?
我用bake命令做了table,用drop,sql命令删除了,那是错误的。所以我通过 bin/cake bake migration DropTableName
然后迁移制作了 drop 迁移文件,并制作了新的 product
table。
我要学习cake中的bake迁移命令php,
所以我创建了一个名为 product
的 table
bin/cake bake migration CreateProduct
和 bin/cake migration migrate
为了再次将其作为训练,我将 table 删除了 drop table product
并删除了迁移 php 文件,并且
bin/cake bake migration CreateTableName
name:string description:text created modified
成功,迁移文件已成功制作
<?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('des', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
]);
$table->addColumn('text', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
]);
$table->addColumn('created', 'datetime', [
'default' => null,
'null' => false,
]);
$table->addColumn('modified', 'datetime', [
'default' => null,
'null' => false,
]);
$table->create();
}
}
并且还制作了迁移文件
<?php
use Migrations\AbstractMigration;
class Migrate 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 找不到!
如何创建一个 table 其名称与删除的 table 相同?
我用bake命令做了table,用drop,sql命令删除了,那是错误的。所以我通过 bin/cake bake migration DropTableName
然后迁移制作了 drop 迁移文件,并制作了新的 product
table。