2015-05-25 73 views
10

我想在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(); 
    }); 
} 
[...] 

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

$ php artisan migrate 
$ php artisan migrate:install 
$ php artisan migrate --pretend 

没有一个返回任何输出并且没有创建表。要填充的数据库存在。

+0

请使用此命令'php artisan make:migration CreateUsersTable --create'创建迁移,然后运行'php artisan migrate' – vps

回答

18

迁移文件必须匹配模式*_*.php,否则将不会被发现。由于users.php与此模式不匹配(它没有下划线),因此该文件将不会被迁移程序找到。

理想情况下,你应该使用人员可以创建迁移文件:

php artisan make:migration create_users_table 

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

您还可以用--create--table切换到加一点点更多的样板,以帮助您开始:

php artisan make:migration create_users_table --create=users 

上迁移的文档可以找到here