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

匆匆过客 提交于 2019-12-10 21:37:56

问题


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?


回答1:


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".




回答2:


When you have problems with your migrations, sometimes

php artisan migrate:refresh

But if your migrations are really broken, and it happens sometimes, you may have to delete all your database tables and then run php artisan migrate again.




回答3:


use Illuminate\Support\Facades\Schema;



来源:https://stackoverflow.com/questions/22291704/one-of-my-migrations-is-not-running-with-the-php-artisan-command-in-laravel-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!