Reputation: 340
I have some table and I want to add new column to this table. I want add string column with nullable default value.
I try add it like that
Schema::table('table', function (Blueprint $table) {
$table->addColumn('string', 'label')->nullable()->change();
});
or
Schema::table('table', function (Blueprint $table) {
$table->addColumn('string', 'label')->nullable();
});
but I have this error here is no column with name 'label' on table.
Upvotes: 1
Views: 975
Reputation: 4449
Using the migration command you can add a new column to the existing table and the command is given below
Use command :
Php artisan make:migration add_column_name_table_name --table=table_name
After this command, one migration is created in “database/migrations”
Schema::table('users', function (Blueprint $table) {
$table->string('custom_id')->after('id')->nullable();
});
After that use another command
Php artisan migrate
Upvotes: 1