我创建了一个迁移,我应该为我的数据库创建表,并插入默认的admin用户.
<?php
//use Yii;
use yii\db\Migration;
use yii\db\Schema;
/**
* Class m180616_200856_create_tables
*/
require_once( __DIR__.'/../config.php');
class m180616_200856_create_tables extends Migration
{
public function up()
{
if (Yii::$app->db->schema->getTable("users",true)===null) {
$this->createTable('users', [
'id' => $this->primaryKey(),
'username' => $this->string(),
'password' => $this->string(),
'authKey' => $this->string(),
'accessToken' => $this->string()
]);
$this->insert('users',array(
'username'=> SUPERUSER_LOGIN,
'password' => md5(SUPERUSER_PASS ),
'authKey' => 'key',
'accessToken' => ''
));
}
}
public function down()
{
echo "m180616_200856_create_tables cannot be reverted.\n";
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行此迁移时,我收到错误:
*** applying m180616_200856_create_tables
Exception 'yii\base\UnknownMethodException' …Run Code Online (Sandbox Code Playgroud)