-1

I developed one api which is responsible for storing user details inside my database ,The table name is users_containers, it will contain some users data now i want to rename that table name to users_data without lossing any data ,How to acheive this thing...

Migration table

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateUsersTable extends Migration
{
    
    public function up()
    {
        Schema::create('users_containers', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('email')->unique();
            $table->timestamp('email_verified_at')->nullable();
          
        });
    }
Devops Training
  • 221
  • 3
  • 15
  • you can use all the methods available in the asnwers. Make sure you change the ```protected $table="new_name"``` in model as well – Nipun Tharuksha Aug 16 '21 at 07:36

2 Answers2

2

To change a table name, you can do this:

Schema::rename('users_containers', 'users_data');
Aless55
  • 2,652
  • 2
  • 15
  • 26
1

Make a new migration:

php artisan make:migration rename_usercontainers_table

then add this code to it:

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class RenameUsersContainersTable extends Migration
{
    
    public function up()
    {
        Schema::rename('users_containers', 'users_data');
    }
}
?>

then try to run migrate command: php artisan migrate

Mohammad H.
  • 856
  • 9
  • 19