#Implicitly inserted columns?

6 messages · Page 1 of 1 (latest)

lunar jackal
#

I have this table schema:

    public function up(): void
    {
        Schema::create('dictionary_modifications', function (Blueprint $table) {
            $table->string('id')->primary();
            $table->foreignIdFor(Dictionary::class)->onDelete('cascade');
            $table->enum('action', ['create', 'read', 'update', 'delete']);
            $table->enum('updated_property', ['front', 'back', 'status']);
            $table->timestamp('created_at');
        });
    }

And this factory for seeding it:

    public function definition(): array
    {
        $dictinoary = Dictionary::all()->first();
        return [
            'dictionary_id' => $dictinoary->id,
            'action' => $this->faker->randomElement(['create', 'read', 'update', 'delete']),
            'updated_property' => $this->faker->randomElement(['front', 'back', 'status']),
        ];
    }

And this is how I seed all tables:

        echo "> Seeding User\n";
        $user = User::factory()->create();
        echo "> Seeding Dictionary\n";
        $dictionary = Dictionary::factory()->create();
        echo "> Seeding Entry\n";
        $entry = Entry::factory()->create();
        echo "> Seeding DictinoaryModification\n";
        $dictionaryModification = DictionaryModification::factory()->create();

The only one that gives me an error when seeding is the last table, with the error message:

> Seeding DictinoaryModification

   Illuminate\Database\QueryException 

  SQLSTATE[42S22]: Column not found: 1054 Unknown column 'updated_at' in 'field list' (Connection: mysql, SQL: insert into `dictionary_modifications` (`entry_id`, `action`, `updated_property`, `id`, `updated_at`, `created_at`) values (9ca44e41-50e7-4ce4-97c7-a7043d2fc93d, read, back, 9ca44e41-544b-41cd-8ed1-eaf132a0e3fd, 2024-07-29 23:16:54, 2024-07-29 23:16:54))

It says "unknown column" which true, yet I don't explicitly add that column!

pulsar quiver
#

No reason not to have updated_at though

lunar jackal
#

As soon as I disabled the timestamps, my explicit one lost it's automatic assignment! @pulsar quiver

#

IG, I'll just do it the default implicit way ¯_(ツ)_/¯