I've got a table, and I want to add ->unsigned() to the id. At the moment, the migration looks like: $table->increments('id');
So I want to do a new migration to set that to unsigned, but there's not much in the documentation to do this. Is this the correct way:
public function up()
{
Schema::table('authors', function($t) {
$t->unsigned('id', 'authors_id_unsigned');
});
}
public function down()
{
Schema::table('authors', function($t) {
$t->dropUnsigned('authors_id_unsigned');
});
}
I'm just guessing here because I can't find it in the docs.
You can modify columns in Laravel 5+, but you have to add the doctrine/dbal dependency to your composer.json file.
public function up()
{
Schema::table('my_table', function (Blueprint $table) {
$table->integer('my_column')->unsigned()->change();
});
}
public function down()
{
Schema::table('my_table', function (Blueprint $table) {
$table->integer('my_column')->change();
});
}
You can't change that kind of details with the Schema Builder.
To change it, you have to run a raw query. To achieve this, your migration should look something like this:
public function up()
{
Schema::table('authors', function($t) {
DB::statement("ALTER TABLE `authors` CHANGE COLUMN `id` `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT FIRST");
});
}
public function down()
{
Schema::table('authors', function($t) {
DB::statement("ALTER TABLE `authors` CHANGE COLUMN `id` `id` INT(11) NOT NULL AUTO_INCREMENT FIRST");
});
}
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