我刚刚学习Laravel,并且有一个工作迁移文件创建用户表。我想填充用户记录作为迁移的一部分:在Laravel迁移文件中填充数据库
public function up()
{
Schema::create('users', function($table){
$table->increments('id');
$table->string('email', 255);
$table->string('password', 64);
$table->boolean('verified');
$table->string('token', 255);
$table->timestamps();
DB::table('users')->insert(
array(
'email' => '[email protected]',
'verified' => true
)
);
});
}
但运行php artisan migrate
时,我收到以下错误:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'vantage.users' doesn't exist
这显然是因为工匠尚未建立该表,但所有文档似乎都表示,有一种使用Fluent Query来迁移数据的方式。
任何人都知道如何?谢谢!
Thankyou Benjamin,这太棒了! –
以及如何插入多个数据? –