我正在尝试在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
- 文件夹中运行这些命令:
$ php artisan migrate
$ php artisan migrate:install
$ php artisan migrate --pretend
它们都没有返回任何输出,也没有创建表。要填充的数据库存在。
答案 0 :(得分:32)
迁移文件必须与模式*_*.php
匹配,否则将无法找到它们。由于users.php
与此模式不匹配(它没有下划线),因此迁移器无法找到此文件。
理想情况下,您应该使用artisan创建迁移文件:
php artisan make:migration create_users_table
这将创建具有相应名称的文件,然后您可以编辑该文件以充实您的迁移。该名称还将包含时间戳,以帮助迁移者确定迁移顺序。
您还可以使用--create
或--table
开关添加更多样板来帮助您入门:
php artisan make:migration create_users_table --create=users
可以找到有关迁移的文档here。
答案 1 :(得分:-1)
在laravel 5中,我们首先需要创建迁移,然后运行迁移
第1步。
php artisan make:migration create_users_table --create=users
第2步。
php artisan migrate
答案 2 :(得分:-3)
为了在表格中给出一个值,我们需要给出一个命令:
php artisan make:migration create_users_table
然后是此命令行
php artisan migrate
......