Yii2 Migration 移动数据到其他 table
Yii2 Migration move data to other table
我有 table:
CREATE TABLE `ticket` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`price` int(11) DEFAULT NULL,
`status` NOT NULL DEFAULT,
`date_created` datetime NOT NULL,
`date_used` datetime DEFAULT NULL,
`used_by_user_id` int(11) DEFAULT NULL,)
ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
并且我创建了 table
$this->createTable('used', [
'id' => $this->primaryKey(),
'ticket_id' => $this->integer()->notNull(),
'date_used' => $this->integer()->notNull(),
'used_by_user_id' => $this->integer()->notNull(),
], 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB');
我想将一些数据(date_used
& used_by_user_id
)从 table ticket
移动到其他 table 用于查询中的迁移 yii2。但是我不知道如果没有 ActiveRecord
& array
怎么办。
$this->execute("
INSERT INTO used (ticket_id, date_used, used_by_user_id)
SELECT id, date_used, used_by_user_id
FROM ticket
WHERE
used_by_user_id IS NOT NULL AND date_used IS NOT NULL
");
只有 sql。 insert into
中不支持 Yii 迁移 select
我有 table:
CREATE TABLE `ticket` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`price` int(11) DEFAULT NULL,
`status` NOT NULL DEFAULT,
`date_created` datetime NOT NULL,
`date_used` datetime DEFAULT NULL,
`used_by_user_id` int(11) DEFAULT NULL,)
ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
并且我创建了 table
$this->createTable('used', [
'id' => $this->primaryKey(),
'ticket_id' => $this->integer()->notNull(),
'date_used' => $this->integer()->notNull(),
'used_by_user_id' => $this->integer()->notNull(),
], 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB');
我想将一些数据(date_used
& used_by_user_id
)从 table ticket
移动到其他 table 用于查询中的迁移 yii2。但是我不知道如果没有 ActiveRecord
& array
怎么办。
$this->execute("
INSERT INTO used (ticket_id, date_used, used_by_user_id)
SELECT id, date_used, used_by_user_id
FROM ticket
WHERE
used_by_user_id IS NOT NULL AND date_used IS NOT NULL
");
只有 sql。 insert into
select