php - Yii2.0高级模板安装小问题
ringa_lee
ringa_lee 2017-04-10 16:00:17
[PHP讨论组]

早上利用Composer安装了Yii2.0的高级版,全部配置完成之后发现登录处出错,报错显示没有对应的用户表,然后对照着Github上的官方文档又看了一遍,发现第三步没有执行,不知道这一步怎么做,求指导。

ringa_lee
ringa_lee

ringa_lee

全部回复(5)
巴扎黑

第三步是执行数据库迁移操作, 关于迁移相关的 文档

  1. 你先建立好数据库

  2. 在common/config/main-local.php中配置数据信息

  3. yii是一个php脚本, 你可以运行 php yii migrate
    会执行 console/migrations 目录下面的迁移脚本, 刚开始这个迁移是建立了一张用户表
    迁移脚本内容如下

<?php

use yii\db\Schema;
use yii\db\Migration;

class m130524_201442_init extends Migration
{
    public function up()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
        }

        $this->createTable('{{%user}}', [
            'id' => Schema::TYPE_PK,
            'username' => Schema::TYPE_STRING . ' NOT NULL',
            'auth_key' => Schema::TYPE_STRING . '(32) NOT NULL',
            'password_hash' => Schema::TYPE_STRING . ' NOT NULL',
            'password_reset_token' => Schema::TYPE_STRING,
            'email' => Schema::TYPE_STRING . ' NOT NULL',

            'status' => Schema::TYPE_SMALLINT . ' NOT NULL DEFAULT 10',
            'created_at' => Schema::TYPE_INTEGER . ' NOT NULL',
            'updated_at' => Schema::TYPE_INTEGER . ' NOT NULL',
        ], $tableOptions);
    }

    public function down()
    {
        $this->dropTable('{{%user}}');
    }
}
ringa_lee

基于basic template的猜测,你试试到项目目录下,执行这个:

./yii migrate
黄舟

打开cmd,定位到项目目录下,键入

yii migrate
ringa_lee

如果是重新安装YII2的话 可以直接把用户表拷贝生成就可以了。第3步的意思主要是配置数据库表等

PHPz

Yii高级模板Migrate

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号