I want to produce the below SQL query,
ALTER TABLE `api`.`users` CHANGE COLUMN `id` `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT ;
in Laravel 5
another abstract layer was introduced, change, after that you can code like this,
public function up()
{
Schema::table('users', function (Blueprint $table) {
//DB::statement("ALTER TABLE `api`.`users`
// CHANGE COLUMN `id` `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT ;");
$table->increments('id')->unsigned()->change();
});
}
What is the way to undo the change, how should I write my down()
?
Unsuccessfully I tried the following.
public function down()
{
//DB::statement("ALTER TABLE `api`.`users`
// CHANGE COLUMN `id` `id` INT(11) NOT NULL AUTO_INCREMENT ;");
$table->increments('id')->change();
}
--- Edit ---
I'm working with an existing table with live data (in fact a replica in my local environment). So I'm afraid perhaps dropping a column is not my option.
You can drop the column and re-add it. Because it's auto incrementing all the existing rows should keep the same ID.
public function down()
{
$table->dropColumn('id');
$table->increments('id');
}
But don't forget, using increments will automatically add unsigned
for you and all of your keys should be unsigned, including any foreign key columns.