工匠,在数据库中创建表

Str*_*amp 27 php laravel laravel-5 artisan laravel-migrations

我试图在Laravel 5中创建mysql表.我创建了一个/project/database/migrations名为的文件users.php:

[...]
public function up()
{
    Schema::create('users', function(Blueprint $table)
    {
        $table->increments('id');
        $table->string('username');
        $table->string('fullname');
        $table->int('number');
        $table->string('email')->unique();
        $table->string('password', 60);
        $table->rememberToken();
        $table->timestamps();
    });
}
[...]
Run Code Online (Sandbox Code Playgroud)

然后我尝试在project-folder中运行这些命令:

$ php artisan migrate
$ php artisan migrate:install
$ php artisan migrate --pretend
Run Code Online (Sandbox Code Playgroud)

它们都没有返回任何输出,也没有创建表.要填充的数据库存在.

pat*_*cus 40

迁移文件必须与模式匹配*_*.php,否则将无法找到它们.由于users.php与此模式不匹配(它没有下划线),因此迁移器将找不到此文件.

理想情况下,您应该使用工匠创建迁移文件:

php artisan make:migration create_users_table
Run Code Online (Sandbox Code Playgroud)

这将创建具有适当名称的文件,然后您可以编辑该文件以充实您的迁移.该名称还将包括时间戳,以帮助迁移者确定迁移的顺序.

您还可以使用--create--table开关添加更多样板来帮助您入门:

php artisan make:migration create_users_table --create=users
Run Code Online (Sandbox Code Playgroud)

有关迁移的文档可以在这里找到.