mardi 20 décembre 2016

laravel schema builder, find columnType autoincrement

I'm working to update an existing database to use autoincremented primary keys. This DB currently has crazy named PK fields with custom values. I need to check each table first to see if it HAS an autoinc field first, then I want to drop it and replace with 'id' field.

I want to do this as a migration, here's what I have so far but I can't seem to identify if the first col is autoincrementing already so I can drop the existing PK and replace. I need to replace the hasColumn with something like a firstColumn then getColumnType...

    foreach ($tableNames as $name)
                if (!Schema::hasColumn($name, 'id')) {
                Schema::table($name, function ($table) {
                    $table->dropPrimary();
                    $table->increments('id')->first();
                });
            }
        }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire