Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

NancyJames's avatar

Field not being created with migration

So I'm creating a very simple companies table but the name field isn't being created, I've dropped tables and migrated fresh multiple times and I can't see what's wrong.


use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('companies', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('companies');
    }
};
0 likes
2 replies
LaryAI's avatar
Level 58

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:

  1. Check for Multiple Migrations
    Ensure you don't have another migration that creates or alters the companies table, possibly overriding or modifying the schema.

  2. Clear All Tables and Migrate Fresh
    Run the following commands to reset your database and apply all migrations from scratch:

    php artisan migrate:fresh
    

    This will drop all tables and re-run all migrations.

  3. Check the Migration Status
    Make sure your migration has actually run:

    php artisan migrate:status
    

    Look for your migration file in the list and ensure it is marked as "Yes".

  4. Inspect the Table Structure
    After running the migrations, check the structure of your companies table directly in your database (using a tool like phpMyAdmin, TablePlus, or the MySQL CLI):

    DESCRIBE companies;
    

    You should see the name column listed.

  5. 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
    
  6. 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.

NancyJames's avatar

clearing the cache seems to have done it, I'd discounted that as there never was a version of the migration without the name field

Please or to participate in this conversation.