| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- namespace app\migrations;
- use yii\db\Migration;
- /**
- * 因为区域管理表不是自增Id。所以需要指定ID 之前有错误数据需要删除
- * Class M250610104039InsertTown
- */
- class M250610104039InsertTown extends Migration
- {
- /**
- * {@inheritdoc}
- */
- public function safeUp()
- {
- // 先执行之前数据的删除 在重新插入
- try {
- $sql = <<<SQL
- DELETE FROM `qimall_town` WHERE (`adcode` = 441303 OR `adcode` = 441302) AND `name` in ('澳头街道', '西区街道', '霞涌街道', '陈江街道', '惠环街道', '沥林镇', '潼侨镇', '潼湖镇');
- INSERT INTO `qimall_town` (`district_id`, `adcode`, `name`, `created_at`, `updated_at`) VALUES (10320, 441303, '澳头街道', 1742278841, 1742278841);
- INSERT INTO `qimall_town` (`district_id`, `adcode`, `name`, `created_at`, `updated_at`) VALUES (10320, 441303, '西区街道', 1742278841, 1742278841);
- INSERT INTO `qimall_town` (`district_id`, `adcode`, `name`, `created_at`, `updated_at`) VALUES (10320, 441303, '霞涌街道', 1742278841, 1742278841);
-
- INSERT INTO `qimall_town` (`district_id`, `adcode`, `name`, `created_at`, `updated_at`) VALUES (10321, 441302, '陈江街道', 1742278841, 1742278841);
- INSERT INTO `qimall_town` (`district_id`, `adcode`, `name`, `created_at`, `updated_at`) VALUES (10321, 441302, '惠环街道', 1742278841, 1742278841);
- INSERT INTO `qimall_town` (`district_id`, `adcode`, `name`, `created_at`, `updated_at`) VALUES (10321, 441302, '沥林镇', 1742278841, 1742278841);
- INSERT INTO `qimall_town` (`district_id`, `adcode`, `name`, `created_at`, `updated_at`) VALUES (10321, 441302, '潼侨镇', 1742278841, 1742278841);
- INSERT INTO `qimall_town` (`district_id`, `adcode`, `name`, `created_at`, `updated_at`) VALUES (10321, 441302, '潼湖镇', 1742278841, 1742278841);
- SQL;
- $this->execute($sql);
- } catch (\Exception $e) {
- // 处理异常
- var_dump($e->getMessage());
- }
- }
- /**
- * {@inheritdoc}
- */
- public function safeDown()
- {
- echo "M250610104039InsertTown cannot be reverted.\n";
- return false;
- }
- }
|