问题
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.
- Delete the tables and columns the migration is supposed to create if they are still there.
- 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"
- Run
composer dump-autoload
- this gets the old migration out of the system's memory - 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