关联写入时提示数据表字段不存在

浏览:10922 发布日期:2016/11/04 分类:求助交流
您好,请问我在按照快速入门的第六章第七小节的代码进行测试时,发现在编写好各个模块的文件后,执行add方法总是提示数据表字段不存在:[ update_time],请问是为什么呢?

controller\User<?php
/**
 * Created by PhpStorm.
 * User: cy
 * Date: 16-11-4
 * Time: 上午10:06
 */

namespace app\index\controller;

use app\index\model\User as UserModel;
use app\index\model\Profile;
class User
{
    public function add()
    {
        $user = new UserModel;
        $user->name = 'thinkphp';
        $user->password = '123456';
        $user->nickname = '流年';
        if ($user->save()){
            //写入关联数据
            $profile = new Profile;
            $profile->truename = '刘晨';
            $profile->birthday = '1977-03-05';
            $profile->address = '中国上海';
            $profile->email = 'thinkphp.qq.com';

            $user->profile()->save($profile);

            return '用户新增成功';

        }else{
            return $user->getError();
        }
    }
}
model\user<?php
/**
 * Created by PhpStorm.
 * User: cy
 * Date: 16-11-4
 * Time: 下午3:34
 */

namespace app\index\model;

use think\Model;
class User extends Model
{

    //开启自动写入时间戳
    protected $autoWriteTimestamp = true;

    //protected $createTime = 'create_time';

    //protected $updateTime = 'update_time';

    //定义自动完成属性
    protected $insert = ['status'=>1];


    //定义关联方法

    public function profile()
    {
        return $this->hasOne('Profile');
    }


}
最佳答案
评论( 相关
后面还有条评论,点击查看>>