skip to Main Content

In the create_users_table I changed the name of the column from ‘name’ to ‘username’. However while setting up the database seeder I get the following error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘name’ in ‘field list’ (Connection: mysql, SQL: insert into users (name, email, email_verified_at, password, remember_token, updated_at, created_at)

This is the line in the DatabaseSeeder:
$user = User::factory()->create();

I tried changing the fillable property in the User model but still same problem. I do not know which file I should change.

2

Answers


  1. Be sure your database has the right column name and try to insert the full object in the seeder example:

    DB:table('users')->insert([
    'username'=> 'username',
    'email' => '[email protected]',
    'password' => Hash:make('mypassword')
    ]);
    

    I am using QueryBuilder, but you can always do it Eloquent and your models.

    Login or Signup to reply.
  2. I think you are searching for a file named:
    UserFactory.php

    it should be located at the path:
    databasefactories

    if you cannot find it, I recommend checking for any other files with similar names in that directory.

    To refresh the database migration:

    php artisan migrate:refresh
    

    To seed the database:

    php artisan db:seed
    

    If you get an error during the migration process, you can try removing the migrations table and then re-running the migration command.

    Please be aware that running the php artisan migrate:refresh command will indeed reset your database and remove all existing data.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search