Laravel Error Message Method method name does not exist

Posted on

This is an article related to the error message shown in the middle of executing php artisan command specifically operated on migration script file. The migration script file is being refreshed by executing the following command explained. The most important which is needed to be focused on is the error message happened in the development process of web-based application using Laravel PHP Framework.

The error message happened upon executing the following command :

php artisan migrate:refresh

This is the actual output of executing the above command :

user@hostname:/var/www/html/laravel-support-ticket# php artisan migrate:refresh
Rolling back: 2017_11_03_095254_create_units_table
Rolled back: 2017_11_03_095254_create_units_table
Rolling back: 2017_11_03_060734_create_services_table
Rolled back: 2017_11_03_060734_create_services_table
Rolling back: 2017_11_02_154132_create_comments_table
Rolled back: 2017_11_02_154132_create_comments_table
Rolling back: 2017_11_02_151921_create_categories_table
Rolled back: 2017_11_02_151921_create_categories_table
Migration not found: 2017_11_02_151257_create_categories_table
Migration not found: 2017_11_02_150646_create_categories_table
Rolling back: 2017_11_02_150552_create_tickets_table
Rolled back: 2017_11_02_150552_create_tickets_table
Rolling back: 2014_10_12_100000_create_password_resets_table
Rolled back: 2014_10_12_100000_create_password_resets_table
Rolling back: 2014_10_12_000000_create_users_table
Rolled back: 2014_10_12_000000_create_users_table
[BadMethodCallException]
Method increment does not exist.
user@hostname:/var/www/html/laravel#

The error comes in the end showing a clear error message :

Method increment does not exist.

The error message is very clear that there is a method called ‘increment’ which cannot be processed because it doesn’t exist. Just try to search every migration script file available in the folder ‘database/migrations’ which has the keyword of ‘increment’. Below is one way which can be used to find out about the migration script contains only ‘increment’ keyword.

user@hostname:/var/www/html/laravel# find database/migrations -type f -print0 | xargs -0 grep -l increment
...
database/migrations/2017_11_05_120717_role.php
...
user@hostname:/var/www/html/laravel#

Apparently the above command ‘find database/migrations’ -type f -print0 | xargs -0 grep -l increment can be explained as follows :

find : It is a command to find specific files in a directory hierarchy
database/migrations : The location which is represented the directory location for finding the specific files
-type f : It is a parameter informing that the one which is being searched has the type of file
-print0 : It is a parameter for printing the output into a standard output which in this context it is printed to a monitor with null character as delimiter
xargs -0 : It is a command which is receiving the output of the find command where it is processed into chunks using null character as a record separator. 
grep -l : It is applying the search pattern finding on each file discovered 

The above pattern on -print0 and -0 is used to make sure there will be no problem with file name which contain spaces.

The above command pattern can be discovered in this link . In the link itself there are lots of command pattern which can be used to search for a specific text pattern. The text pattern itself in the context of this article is ‘increment’. The correct one which is the correct method is ‘increments’. It is used to specify a column to be configured with auto_increment feature at the time the migration script file defined with it is being executed. It is shown as follows :

class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->rememberToken();
$table->timestamps();
});
}

The method $table->increments(‘id’); will eventually the representation for creating a new column named ‘id’ with auto_increment feature.

One thought on “Laravel Error Message Method method name does not exist

Leave a Reply