How do I properly change / update my migration, I am using Laravel 5.1.
The Docs said that I should use change to update the column e.g.:
$table->string('color', 10)->change();
But where do I have to put it in the migration and what command do I have to use to update just a simply php artisan migrate?
I tried this so far:
public function up()
{
Schema::create('products', function (Blueprint $table)) {
$table->string('color', 5);
});
Schema::table('products', function (Blueprint $table)) {
$table->string('color', 10)->change();
});
}
And used this command:
php artisan migrate
But it did not change.
First, create new migration to change existing table column(s).
php artisan make:migration update_products_table
Then you should do this inside up()
method in your new migration:
Schema::table('products', function (Blueprint $table) {
$table->string('color', 10)->change();
});
So, you'll have two migrations. First did already create products
table with wrong length of the color
string.
Second migration will change color
string length from 5 to 10.
After you created seconds migration, run php artisan migrate
again and changes will apply to a 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