s.sanketsp
4 years ago
1247
2
Laravel

Laravel migrate with renameColumn

Posted 4 years ago by s.sanketsp

I am facing a strange exception saying

[Doctrine\DBAL\Schema\SchemaException]                     
There is no column with name 'id' on table 'user_master'. 

But the column id exists in the user_master table, find below the description of the table

mysql> DESC user_master;
+----------------+------------------+------+-----+---------------------+----------------+
| Field          | Type             | Null | Key | Default             | Extra          |
+----------------+------------------+------+-----+---------------------+----------------+
| id             | int(10) unsigned | NO   | PRI | NULL                | auto_increment |
| name           | varchar(255)     | NO   |     | NULL                |                |
| email          | varchar(255)     | NO   | UNI | NULL                |                |
| password       | varchar(60)      | NO   |     | NULL                |                |
| remember_token | varchar(100)     | YES  |     | NULL                |                |
| created_at     | timestamp        | NO   |     | 0000-00-00 00:00:00 |                |
| updated_at     | timestamp        | NO   |     | 0000-00-00 00:00:00 |                |
+----------------+------------------+------+-----+---------------------+----------------+

The problem seems to be in the migration that contains the renameColumn(). Below is the up() of the migration.

public function up()
{
    Schema::table('user_master', function(Blueprint $table)
    {
        $table->renameColumn('id', 'user_id');
                $table->renameColumn('name', 'first_name');
        });
}

I use Laravel 5.0 and have updated the project vendor using composer update command.

I searched a lot about this, and found that there was indeed a problem with renameColumn(). Following are a few links, that I can relate to: http://stackoverflow.com/questions/29907605/rename-column-name-using-laravel-migration-using-doctrine-dbal-gives-error https://laracasts.com/discuss/channels/eloquent/php-artisan-migraterollback

I am a point where it is very difficult for me to change the migration_files as there are more than dozens of other migration files after the migration file in question.

Please sign in or create an account to participate in this conversation.