我正在使用 Laravel 工厂来为我的数据库做种,但我不明白为什么会抛出这个错误。(显示在底部)。
这是我的第一篇文章,所以请让我知道我如何能够更清楚地描述问题:)
PollAnswerFactory.php
$factory->define(PollAnswer::class, function (Faker\Generator $faker) {
$answer_text = $faker->word;
$answer_order = rand(0,10);
$question_id = rand(1,500);
return [
"answer_text" => $answer_text,
"answer_order" => $answer_order,
"question_id" => $question_id,
];
});
Run Code Online (Sandbox Code Playgroud)
PollAnswer.php
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class PollAnswer extends Model {
/**
* @var bool Indicates if the model should be timestamped.
*/
public $timestamps = false;
/**
* @var string The database table for this model.
*/
protected $table = 'poll_answers';
/**
* The connection name …Run Code Online (Sandbox Code Playgroud)