mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 14:26:54 +08:00
Add migration file example for DbSession (#14227) [skip ci]
Creating a `char` primaryKey in a migration is non-obvious. Used solution from this [issue comment](https://github.com/yiisoft/yii2/issues/10889#issuecomment-302995086).
This commit is contained in:

committed by
Alexander Makarov

parent
e2218cbbae
commit
85294ab4e3
@ -178,6 +178,31 @@ where 'BLOB' refers to the BLOB-type of your preferred DBMS. Below are the BLOB
|
|||||||
the length of the `id` column. For example, if `session.hash_function=sha256`, you should use a
|
the length of the `id` column. For example, if `session.hash_function=sha256`, you should use a
|
||||||
length 64 instead of 40.
|
length 64 instead of 40.
|
||||||
|
|
||||||
|
Alternatively, this can be accomplished with the following migration:
|
||||||
|
|
||||||
|
```php
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\db\Migration;
|
||||||
|
|
||||||
|
class m170529_050554_create_table_session extends Migration
|
||||||
|
{
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
$this->createTable('{{%session}}', [
|
||||||
|
'id' => $this->char(64)->notNull(),
|
||||||
|
'expire' => $this->integer(),
|
||||||
|
'data' => $this->binary()
|
||||||
|
]);
|
||||||
|
$this->addPrimaryKey('pk-id', '{{%session}}', 'id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
$this->dropTable('{{%session}}');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Flash Data <span id="flash-data"></span>
|
### Flash Data <span id="flash-data"></span>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user