m190203_071900_create_address_table.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. use yii\db\Migration;
  3. use yii\db\Schema;
  4. /**
  5. * Handles the creation of table `{{%address}}`.
  6. */
  7. class m190203_071900_create_address_table extends Migration
  8. {
  9. public $tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB';
  10. /**
  11. * @inheritdoc
  12. */
  13. public function up()
  14. {
  15. /**
  16. * 收货人姓名、电话、省、市、区、详细地址、是否默认、用户id
  17. */
  18. $this->createTable('{{%address}}', [
  19. 'id' => Schema::TYPE_PK,
  20. 'user_id' => $this->integer(11)->notNull()->comment('用户ID'),
  21. 'name' => Schema::TYPE_STRING . "(20) NOT NULL COMMENT '收货人'",
  22. 'tel' => Schema::TYPE_STRING . "(11) NOT NULL COMMENT '手机号'",
  23. 'province' => Schema::TYPE_STRING . "(50) NOT NULL COMMENT '省份'",
  24. 'city' => Schema::TYPE_STRING . "(50) NOT NULL COMMENT '城市'",
  25. 'area' => Schema::TYPE_STRING . "(50) NOT NULL COMMENT '区域'",
  26. 'detail' => Schema::TYPE_STRING . "(200) NOT NULL COMMENT '详细地址'",
  27. 'created_at' => Schema::TYPE_INTEGER . "(11) NOT NULL",
  28. 'updated_at' => Schema::TYPE_INTEGER . "(11) NOT NULL",
  29. 'status' => Schema::TYPE_SMALLINT . "(1) NOT NULL DEFAULT '1' COMMENT '状态'",
  30. ], $this->tableOptions);
  31. }
  32. /**
  33. * @inheritdoc
  34. */
  35. public function down()
  36. {
  37. $this->dropTable('{{%address}}');
  38. }
  39. }