Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

One of my migrations is not running with the php artisan command in Laravel 4

I have several migrations I am running in Laravel 4. I use the php artisan migrate:rollback and php artisan migrate commands to populate the tables. Interestingly enough, one of my migrations has stopped working (cannot roll back). All of the others are working fine. I haven't changed anything to my knowledge.

The migration in question is named: 2013_06_19_050252_create_artists_table.php

And it looks like so:

    <?php

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

class CreateArtistsTable extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('artists', function(Blueprint $table) {
            $table->increments('id');
            $table->string('url_tag')->unique();
            $table->string('username');

            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('artists');
    }

}

I have no idea why this isn't working. Any ideas what could be going on?

like image 800
user1072337 Avatar asked Dec 03 '22 20:12

user1072337


1 Answers

I had the same problem and did something similar to this to fix it. This is what worked for me.

  1. Delete the tables and columns the migration is supposed to create if they are still there.
  2. Rename the migration in the app/database/migrations file by incrementing the last number in the migration file's name by one. Example: rename "2014_06_01_190448_create_users.php" to "2014_06_01_190449_create_users.php"
  3. Run composer dump-autoload - this gets the old migration out of the system's memory
  4. Rerun php artisan migrate in the command line

The file system basically thinks this is a new migration, so it gives it a "fresh start".

like image 50
user3413723 Avatar answered May 06 '23 03:05

user3413723