Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename table using migration in Laravel

I am running a migration to rename a table but I get an odd error.

public function up()
{   
    Schema::rename($accounts, $feeds);
}   

public function down()
{   
    Schema::rename($feeds, $accounts);
}   

Error:

Undefined variable: accounts

Table definitely exists. Any idea what might be the issue?

like image 817
A.J Avatar asked Feb 07 '18 19:02

A.J


People also ask

Can I rename migration in laravel?

Yes, you can name them however you want, but they will run in alphabetical order (which is why laravel timestamps them). Also you can change a migrations name after the fact (you've already run the migration).


1 Answers

You should use string and not variable:

public function up()
{   
    Schema::rename('accounts', 'feeds');
}   

public function down()
{   
    Schema::rename('feeds', 'accounts');
}   
like image 88
Alexey Mezenin Avatar answered Nov 14 '22 22:11

Alexey Mezenin