如何在Laravel中构建一个迁移?

时间:2016-07-20 06:34:16

标签: laravel laravel-5.2

我做了一次迁移。我怎样才能只构建这个文件?

我试过了:

 php artisan make:migration filename.php
 php artisan make:migration filename
 php artisan make:migration tablename

3 个答案:

答案 0 :(得分:2)

你可以真正做到:

php artisan make:migration the_name_of_your_migration_file --create=table_name

或者,如果您想更新现有表格,

php artisan make:migration add_column_to_existing_table --table=table_name

这是docs

答案 1 :(得分:1)

我认为我们不能使用文件名进行迁移。

但是,您可以注释掉该功能以避免它们运行。

此外,一旦您迁移并添加新的迁移文件,php artisan migrate将只运行新的迁移,因此您可以一次性执行此操作。

答案 2 :(得分:1)

您需要使用create_users_table.create并且必须使用表。

如果您使用下面的one.it将生成with schema

`php artisan make:migration create_users_table --create=users`

如果你使用下面的一个。它将使用out schema

创建
php artisan make:migration create_filename_table

创建的表存在于database-> migrations文件夹中  添加您想要的字段

在您的迁移表中添加

<?php

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

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name')->unique();
            $table->string('email');
            $table->string('password', 60);
            $table->string('photo')->nullable();
            $table->enum('theme', array_values(config('myespaceadmin.application.themes')))->nullable();
            $table->boolean('status');
            $table->boolean('is_delete');
            $table->rememberToken();
            $table->timestamps();
        });
    }

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

最后在控制台php artisan migrate

相关问题