Here is my code using safeUp
<?php
use yii\db\Schema;
class m140309_090452_add_payment_inform extends \yii\db\Migration
{
public function safeUp()
{
$this->createTable("tbl_bank", [
'bank_id' => 'smallint(6) NOT NULL AUTO_INCREMENT',
'bank_name' => Schema::TYPE_STRING,
'PRIMARY KEY (`bank_id`)'
]);
// $this->addPrimaryKey("bank_id_pk", "tbl_bank", "bank_id");
$this->batchInsert("tbl_bank", ['bank_name'],
[['ไทยพาณิชย์'], ['กสิกรไทย'], ['กรุงเทพ'], ['ทหารไทย'], ['กรุงไทย'], ['ออมสิน'], ['ธนชาติ']]);
$this->createTable("tbl_bank_account", [
'bank_account_id' => 'int(11) NOT NULL AUTO_INCREMENT',
'account_name' => Schema::TYPE_STRING,
'bank_id' => Schema::TYPE_SMALLINT,
'account_number' => Schema::TYPE_INTEGER,
'uid' => 'integer',
'PRIMARY KEY (`bank_account_id`)'
]);
// $this->addPrimaryKey("bank_account_id_pk", "tbl_bank_account", "bank_account_id");
$this->createIndex("bank_id_account_index", "tbl_bank_account", "bank_id");
$this->addForeignKey("bank_id_account_fk", "tbl_bank_account", "bank_id", "tbl_bank", "bank_id", 'RESTRICT', 'RESTRICT');
$this->createIndex("uid_bank_account_index", "tbl_bank_account", "uid");
$this->addForeignKey("uid_bank_account_fk", "tbl_bank_account", "uid", "tbl_user", "uid", 'RESTRICT', 'RESTRICT');
$this->createTable("tbl_payment", [
'payment_id' => 'int(11) NOT NULL AUTO_INCREMENT',
'order_id' => Schema::TYPE_SMALLINT,
'account_name' => Schema::TYPE_STRING,
'bank_id' => Schema::TYPE_SMALLINT,
'account_number' => Schema::TYPE_SMALLINT,
'payer_id' => Schema::TYPE_SMALLINT,
'payee_id' => Schema::TYPE_SMALLINT,
'amount' => Schema::TYPE_FLOAT,
'pay_date' => Schema::TYPE_DATETIME,
'remark' => Schema::TYPE_STRING,
'PRIMARY KEY (`payment_id`)'
]);
// $this->addPrimaryKey("payment_id_pk", "tbl_payment", "payment_id");
$this->createIndex("payment_order_index", "tbl_payment", "order_id");
$this->addForeignKey("payment_order_fk", "tbl_payment", "order_id", "tbl_order", "order_id", 'RESTRICT', 'RESTRICT');
$this->createIndex("payer_user_index", "tbl_payment", "payer_id");
$this->addForeignKey("payer_user_fk", "tbl_payment", "payer_id", "tbl_user", "uid", 'RESTRICT', 'RESTRICT');
$this->createIndex("payee_user_index", "tbl_payment", "payee_id");
$this->addForeignKey("payee_user_fk", "tbl_payment", "payee_id", "tbl_user", "uid", 'RESTRICT', 'RESTRICT');
$this->createTable("tbl_shipment", [
'shipment_id' => 'int(11) NOT NULL AUTO_INCREMENT',
'order_id' => Schema::TYPE_SMALLINT,
'receiver_name' => Schema::TYPE_STRING,
'address' => Schema::TYPE_STRING,
'postal_code' => Schema::TYPE_INTEGER,
'sender_id' => Schema::TYPE_SMALLINT,
'receiver_id' => Schema::TYPE_SMALLINT,
'track_code' => Schema::TYPE_FLOAT,
'shipment_method' => Schema::TYPE_SMALLINT,
'send_date' => Schema::TYPE_DATETIME,
'remark' => Schema::TYPE_STRING,
'PRIMARY KEY (`shipment_id`)'
]);
// $this->addPrimaryKey("shipment_id_pk", "tbl_shipment", "shipment_id");
$this->createIndex("shipment_order_index", "tbl_shipment", "order_id");
$this->addForeignKey("shipment_order_fk", "tbl_shipment", "order_id", "tbl_order", "order_id", 'RESTRICT', 'RESTRICT');
$this->createIndex("sender_user_index", "tbl_shipment", "sender_id");
$this->addForeignKey("sender_user_fk", "tbl_shipment", "sender_id", "tbl_user", "uid", 'RESTRICT', 'RESTRICT');
$this->createIndex("receiver_user_index", "tbl_shipment", "receiver_id");
$this->addForeignKey("receiver_user_fk", "tbl_shipment", "receiver_id", "tbl_user", "uid", 'RESTRICT', 'RESTRICT');
}
public function safeDown()
{
$this->delete("tbl_bank_account");
$this->delete("tbl_payment");
$this->delete("tbl_shipment");
$this->delete("tbl_bank");
}
}
but the table also still appear, (it should be rollbacked ?)
Here is the result in my console…
Please advise,