Answer the question
In order to leave comments, you need to log in
How to create JSON field in migration for MySQL?
Hello!
Yii2
In the migration in the safeUp() method, I create a table for MySQL.
$this->createTable('mytable', [
'id' => $this->primaryKey(11)->unsigned(),
'field_1' => $this->string(32)->notNull()->unique(),
'field_2' => $this->string(100)->notNull()->unique(),
'status' => $this->smallInteger(3)->notNull()->unsigned()->defaultValue(1),
'dt_create' => $this->dateTime()->notNull(),
'dt_update' => $this->dateTime()->notNull(),
'param' => 'JSON NOT NULL', // Тут нужно создать поле типа JSON
], $tableOptions);
'param' => 'JSON NOT NULL',
Answer the question
In order to leave comments, you need to log in
Goodnight.
There is no such field type in the documentation.
Dostring()->notNull();
Look for third party extensions. For example, for postgre there is https://github.com/Tigrov/yii2-pgsql, which will allow you to work normally with json, I think there is also for mysql. But I agree with matperez - 'param' => 'JSON NOT NULL',
this is the correct solution.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question