0

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!

9
  • What do your mirgation files look like and what have you named them? Commented May 11, 2017 at 9:09
  • I changed my database and ran php artisan migrate command again: The changes are done in migration file or directly on database? Commented May 11, 2017 at 9:11
  • I created them with php artisan make:migration create_name_of_table Commented May 11, 2017 at 9:14
  • Have you tried php artisan migrate --path="database/migrations"? Commented May 11, 2017 at 9:17
  • @Mayank Pandeyz directly on database, nothing exists in database except migrations table and my migrations table is empty! Commented May 11, 2017 at 9:18

3 Answers 3

3

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
Sign up to request clarification or add additional context in comments.

1 Comment

I understand the concept, thanks! but I don't know where is wrong with my code. still I can't migrate my migration files !
0

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.

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.