如何使用OctoberCMS迁移在现有完整表中添加新的NOT NULL列

I have a table with a simple structure (id, name and timestamps).

I need to add a slug but the system is already running and I need the slug in the database to be Unique and NOT NULL (therefore forbidding me to use a default value).

How I add a migration file to add this column and fill with with something similar to slug(name) in the Migration file ?

public function up() {
    Schema::table('departments', function(Blueprint $table) {
        $table->string('slug');
    });
}

In your migration you may specify a default value for the column by doing:

// ...
$table->string('slug')->default('my-default-slug');
// ...

This will effectively set my-default-slug as value for every record that already exists inside departments at the time you run your migration. However, as far as I know does this setting not prevent modifications to any record where the slug is being set to an empty string afterwards. That's the whole thing with strings, an empty string is still a valid string to your database.

See the Laravel docs for more info on column modifiers.

EDIT

In response to the comment below, there is a fine package available for automatic slug generation based on another attribute of an Eloquent model.