Using a Postgres with Yii2 created a new ENUM
type in postgresql with
createCommand("CREATE TYPE colorEnum AS ENUM ('red', 'black', 'white'););
How can I use it then in Yii2 Migrate class when creating a table, like:
$this->createTable('myTable’, [
'color' => 'what should go here?'
Any of the following should work, including what @rob006 did suggest as comment:
public function safeUp()
{
$this->execute("CREATE TYPE colorEnum AS ENUM ('red', 'black', 'white')");
$this->createTable('myTable', [
"color0" => "colorEnum",
"color1" => "colorEnum default 'black'",
"color2" => $this->getDb()->getSchema()->createColumnSchemaBuilder("colorEnum default 'black'"),
];
// ...
}
public function safeDown()
{
// ...
$this->execute('DROP TYPE colorEnum');
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.