General error: 1364 Field 'remember_token' doesn't have a default value

假装没事ソ 提交于 2019-12-22 18:44:28

问题


I m new to laravel. I wanted to insert the admin credentials into database.

public function verify() {
    $username = Input::get('username');
    $password = Input::get('password');
    if (!Admin::count()) {
        $user = new Admin;
        $user->username = Input::get('username');
        $user->password = $user->password = Hash::make(Input::get('password'));
        $user->save();
        return Redirect::to('/admin/login');
    } else {

        if (Auth::attempt(array('username' => $username, 'password' => $password))) {
            echo("i m in if");
            if (Session::has('pre_admin_login_url')) {
                $url = Session::get('pre_admin_login_url');
                Session::forget('pre_admin_login_url');
                return Redirect::to($url);
            } else {
                $admin = Admin::where('username', 'like', '%' . $username . '%')->first();
                Session::put('admin_id', $admin->id);
                return Redirect::to('/admin/report')->with('notify', 'installation Notification');
            }
        } else {
            return Redirect::to('/admin/login?error=1');
        }
    }

Admin Model:

use Illuminate\Auth\UserTrait;

use Illuminate\Auth\UserInterface;

use Illuminate\Auth\Reminders\RemindableTrait;

use Illuminate\Auth\Reminders\RemindableInterface;

class Admin extends Eloquent implements UserInterface, RemindableInterface {

    use UserTrait, RemindableTrait;

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'admin';

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = array('password', 'remember_token');

I have changed the database to default value to 'null' but still it gives the same error.This was the application built by code-canyon i haven't know about the querying parameter in which files are they exists.

Result:SQLSTATE[HY000]: General error: 1364 Field 'remember_token' doesn't have a default value (SQL: insert into admin (username, password, updated_at, created_at)values(admin@taxinow.com,y$csyEcrhERoQEszmxNmiOG.bcAZtwC8xeGiF2xyKTd2YLhEbjixm.m,2017-09-21 08:34:24, 2017-09-21 08:34:24))

Any help would be appreciated. Thanks.


回答1:


i solved this issue on my application, and i want you to try the same.. go to your users table and edit the remember_token field, update the default column to NULL.

once this is done, try running the application again, it should work this time. But if you were using migrations to update your database schema(fields/properties), you could rollback and make this adjustment to that column by adding this nullable() to the remember_token string...

$table->string('remember_token')->nullable();

i hope this helps.

Regards.



来源:https://stackoverflow.com/questions/46341965/general-error-1364-field-remember-token-doesnt-have-a-default-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!