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
Be sure your database has the right column name and try to insert the full object in the seeder example:
I am using QueryBuilder, but you can always do it Eloquent and your models.
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:
To seed the database:
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.