我的一次迁移没有在 Laravel 4 中使用 php artisan 命令运行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22291704/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 09:09:31  来源:igfitidea点击:

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

phplaravellaravel-4

提问by user1072337

I have several migrations I am running in Laravel 4. I use the php artisan migrate:rollbackand php artisan migratecommands 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.

我在 Laravel 4 中运行了几个迁移。我使用php artisan migrate:rollbackphp artisan migrate命令来填充表。有趣的是,我的一个迁移已停止工作(无法回滚)。所有其他人都工作正常。我没有改变我的知识。

The migration in question is named: 2013_06_19_050252_create_artists_table.php

有问题的迁移被命名为: 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?

我不知道为什么这不起作用。任何想法可能会发生什么?

回答by user3413723

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 migratein the command line
  1. 删除迁移应该创建的表和列,如果它们仍然存在。
  2. 通过将迁移文件名称中的最后一个数字加一来重命名 app/database/migrations 文件中的迁移。示例:将“2014_06_01_190448_create_users.php”重命名为“2014_06_01_190449_create_users.php”
  3. 运行composer dump-autoload- 这会从系统内存中获取旧的迁移
  4. php artisan migrate在命令行中重新运行

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

文件系统基本上认为这是一次新的迁移,因此给了它一个“重新开始”。

回答by Antonio Carlos Ribeiro

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

但是,如果您的迁移真的被破坏了,并且有时会发生这种情况,您可能必须删除所有数据库表,然后php artisan migrate再次运行。

回答by Amr Ibrahim

use Illuminate\Support\Facades\Schema;

使用 Illuminate\Support\Facades\Schema;