Your migration code looks correct, so the issue is likely not with the migration itself but with how it's being run or with your database state. Here are some steps to troubleshoot and resolve the issue:
-
Check for Multiple Migrations
Ensure you don't have another migration that creates or alters thecompaniestable, possibly overriding or modifying the schema. -
Clear All Tables and Migrate Fresh
Run the following commands to reset your database and apply all migrations from scratch:php artisan migrate:freshThis will drop all tables and re-run all migrations.
-
Check the Migration Status
Make sure your migration has actually run:php artisan migrate:statusLook for your migration file in the list and ensure it is marked as "Yes".
-
Inspect the Table Structure
After running the migrations, check the structure of yourcompaniestable directly in your database (using a tool like phpMyAdmin, TablePlus, or the MySQL CLI):DESCRIBE companies;You should see the
namecolumn listed. -
Check for Caching Issues
Sometimes, Laravel caches the schema. Try clearing any cache:php artisan config:clear php artisan cache:clear php artisan view:clear -
Verify the Migration File
Double-check that the migration file you posted is the one being executed, and that you don't have another migration with the same table name.
Summary:
Your migration code is correct:
Schema::create('companies', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
});
If the name field is still not being created after following the above steps, please post the output of php artisan migrate:status and the result of DESCRIBE companies; for further troubleshooting.