How to set a comment on table using Laravel Schema Builder?
Column set:
public function up() { Schema::create('vendors', function (Blueprint $table) { $table->comment('not working - error'); // not working - error $table->increments('id'); $table->string('vendor', 255)->comment('Some comment.'); $table->timestamps(); }); }
But for the table?
The Laravel Schema class provides a database agnostic way of manipulating tables. It works well with all of the databases supported by Laravel, and has a unified API across all of these systems.
A foreign key is a field that is used to establish the relationship between two tables via the primary key (You can also use a non-primary field but not recommended). In this tutorial, I show how you can add a foreign key constraint while creating a table using migration in the Laravel 9 project.
How to change data type of column in laravel 9 migration ? Step 1 : Install doctrine/dbal package. Step 2 : Generate migration file. Step 3 : Open generated migration file and update.
Well I don't have a nice answer for you, but at least it works.
Here it is:
public function up() { $tableName = 'vendors'; Schema::create($tableName, function (Blueprint $table) { $table->increments('id'); $table->string('vendor', 255)->comment('Some comment.'); $table->timestamps(); }); DB::statement("ALTER TABLE `$tableName` comment 'My comment'"); }
Just add a DB statement after creating your table.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With