Erfan
Erfan

Reputation: 35

laravel 5.4 - php artisan migrate command doesn't work

I have four migrations file and when I run php artisan migrate in the command line it says:

Nothing to migrate

I also tried with php artisan migrate --database=vcp:

Database [vcp] not configured.

I used another database in my .env file and ran php artisan migrate command again:

Migration table created successfully.
Nothing to migrate. 

running

php artisan migrate:refresh, php artisan migrate:reset, php artisan migrate:status, php artisan migrate --path="database/migrations/migration_file" whit these messages

Nothing to rollback.
Nothing to migrate.
No migrations found

and

composer dump-autoload or composer update

didn't help.

here is my .env file

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=vcp
DB_USERNAME=root
DB_PASSWORD=secret

my 2017_05_10_201750_add_columns_to_users.php

<?php

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

class AddColumnsToUsers extends Migration
   {
       /**
         * Run the migrations.
         *
         * @return void
        */
       public function up()
      {
            Schema::table('users', function (Blueprint $table) {
                $table->string('status')->default('online');
                $table->string('api_token');
           });
       }

     /**
      * Reverse the migrations.
      *
      * @return void
     */
    public function down()
     {
         Schema::table('users', function (Blueprint $table) {
            $table->dropColumn('status');
            $table->dropColumn('api_token');
        });
     }
} 

please help!

Upvotes: 0

Views: 4681

Answers (3)

Aldo Prinzi
Aldo Prinzi

Reputation: 21

Sometimes you write your Migration function by hand, as I do, copying and pasting an old one, and changing the filename by hand. Ex: the file 2021_10_13_082805_insert_fields_pages_table.php If this is the same situation, take care to the class name, it must contain a name that reflects the filename. In this example:

class InsertFieldsPagesTable extends Migration

If you forget to change the class name, migrations says nothing and do nothing.

Upvotes: 0

Ehi
Ehi

Reputation: 208

Here's what worked for me:

First, delete all your database tables including the migrations table. Second, the update method up() of your AddColumnsToUsers file like this:

public function up()
    {
    DB::beginTransaction();
    try {

        Schema::table('users', function (Blueprint $table) {
            $table->string('status')->default('online');
            $table->string('api_token');
       });

    DB::commit();
    } catch (PDOException $e) {
        DB::rollBack();
        $this->down();
    }
}

This checks your database to see if table already exists, it creates the table if it doesn't exist and rollbacks if it does. Let me know if this worked.

Upvotes: 0

Mayank Pandeyz
Mayank Pandeyz

Reputation: 26258

As you have already stated in above comments, The changes are done directly on database. Then Nothing to migrate. is correct.

Try to understand the concept, migration contains the table structure in files and when you run migration these tables are created in database. When ever you make changes in migration file, you have to again run the migration so that these changes are reflected back to database table. So the flow is:

migration file -> database table

not

database table -> migration file

Upvotes: 3

Related Questions