0
votes

Hi i am using laravel v5.5 and am getting the error below when i run this command

php artisan migrate --seed

please advice how i can fix the error :

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'email_verified_at' in 'field list' (SQL: insert into users (name, email,email_verified_at, password, created_at, updated_at) values (Admin Admin, [email protected], 2020-02-27 13:17:35, $2y$10$0 J3IWuCGVzgfPlP8UgfOK.MjNs2R.m5Jri43SPK3VXSy1NDZHKt4u, 2020-02-27 13:17:35, 2020-02-27 13:17:35)

In Connection.php line 452

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'email_verified_at' in 'field list')

if i am to add new columns to the database using laravel can you assist how i can do it .

Thank you in advance.

3
I am using Laravel 5.5tinoe m
make sure the field email_verified_at exists in users table. check user table and if you don't find it in add email_verified_at field.Dilip Hirapara
I believe email verification is not available on laravel 5.5. I guess you copied factory file from laravel >= 5.7. You can remove email_verified_at field from user factory file or upgrade your laravel to >= 5.7train_fox
Can you edit your post to show us your user migration, factory, and seeder?Kyle Corbin Hurst
I think @train_fox is correctItsEdgar94

3 Answers

0
votes

You have to create a migration. Laravel provide an Authentification system, just use php artisan make:auth.

It will generate a migration inside database/migrations/00xx[...].php For apply this migration, you have to run the command: php artisan migrate

This will create all tables and columns. Once that is done, you can use the Authentification system.


If you want to create your own migration (for adding a new column, for example), you can run: php artisan make:migration add_address_to_users_table (to add a column address in users table).

This will create a new folder inside of database/migrations and you just have to edit it using this documentation: https://laravel.com/docs/5.8/migrations

0
votes

There is two way to fix this problem

As they mention in the comment section you use laravel v5.5 and get a seeder file from higher version that has this new column email_verified_at

First way

remove from your seeder file any seeding for the column called email_verified_at

Second way

In your users migration file edit it to be like this one

    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            ...........
            $table->timestamp('email_verified_at')->nullable();
            ...........
            $table->timestamps();
        });
    }

According to your laravel version i recommend you to use the first way is to delete the email_verified_at from your seeder because it's functionallty not suportted in laravel v5.5 and lower

0
votes

make sure your User Factory attributes = your users table attributes (that is not signed automatically or Could be Null "Null-able" ) like

In your UserFactory

public function definition()
{
    return [
        'name' => $this->faker->name,
        'email' => $this->faker->unique()->safeEmail,
        'email_verified_at' => now(),
        'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
        'remember_token' => Str::random(10),
    ];
}

and in your users table

public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->id();
        $table->string('name');
        $table->string('email')->unique();
        $table->timestamp('email_verified_at')->nullable();
        $table->string('password');
        $table->rememberToken();
        $table->timestamps();
    });
}