laravel迁移创建了不同的模式


laravel migration creates different schema

我正在观看Laracast标题为"Laracast Digging In"的教程,第一部分演示了如何通过实践来使用雄辩。

# app/models/tasks.php
class tasks extends Eloquent{
}

然后继续执行
php artisan migration:make create_tasks_table --create --table="tasks"

然后生成一个迁移文件,看起来像这样。

<?php
use Illuminate'Database'Schema'Blueprint;
use Illuminate'Database'Migrations'Migration;
class CreateTasksTable extends Migration {
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create("tasks", function(Blueprint $table)
        {
            $table->increments("id"); 
                        $table->timestamps(); 
        });
    }
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop("tasks");
    }
}

虽然我做了完全相同的事情,但我得到的结果略有不同

<?php
use Illuminate'Database'Schema'Blueprint;
use Illuminate'Database'Migrations'Migration;
class CreateTasksTable extends Migration {
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('tasks', function(Blueprint $table)
        {
            //
        });
    }
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('tasks', function(Blueprint $table)
        {
            //
        });
    }
}

正如你所看到的,撇开我省略的方法不谈

$table->increments("id"); 
$table->timestamps(); 

它在这里用table完全取代了create

Schema::table('tasks', function(Blueprint $table)
        ^^ is 'create' in the tutorial. 

为什么,这是真的吗。如果我只是忽略了这一点,并开始遵循教程,我将无法获得任何工作。我不想手动修改它,那么为什么会发生这种情况,以及我如何解决它。

您使用了错误的命令

基于Laravel教程使用这个:

用于创建表格

php artisan migrate:make create_tasks_table --create=tasks

用于更新表格

php artisan migrate:make create_tasks_table --table=tasks

基本上,您需要使用--create--table,而不是两者都使用。当您使用--create时,迁移将使用Schema::create,指示迁移将创建一个表

当您使用--table时,迁移将是Schema::table,指示表将被更新

使用--table="tableName"(Schema::table)更新表,或使用--create="tableName"(Schema::create)创建新表。

我很确定在您学习的教程中JeffreyWay/Laravel-4-发电机。如果您对Laravel4感到满意,请忽略生成器,并根据要执行的操作通过创建或删除来替换"table"。

抱歉我的英语不好