我有两个模型 Poll 和 DuplicatePoll
与各自的表格:
Schema::create('polls', function (Blueprint $table) {
$table->id();
$table->text('status');
$table->timestamps();
});
Schema::create('duplicate_polls', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('poll_id');
$table->timestamp('created_at')->useCurrent();
$table->foreign('poll_id')
->references('id')
->on('polls');
});
当我用 tinker 为 DuplicatePolls 创建一个值时,我收到以下错误:
App\Models\DuplicatePoll::factory()->create(['poll_id'=>10]); PHP 致命错误:在第 1 行的 Psy Shell 代码中找不到类“App/Models/DuplicatePoll”
在 DuplicatePoll 工厂:
<?php
namespace Database\Factories;
use App\Models\DuplicatePoll;
use App\Models\Poll;
use Illuminate\Database\Eloquent\Factories\Factory;
class DuplicatePollFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = duplicatePoll::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'poll_id' => Poll::factory()->create(),
];
}
}
更新:
我运行了 composer-dump 自动加载,现在我得到了错误:
App\Models\DuplicatePoll::factory()->create(['poll_id'=>10]); 使用消息'SQLSTATE [42S22] 照亮/数据库/查询异常:找不到列:1054 '字段列表'中的未知列'updated_at'(SQL:插入duplicate_polls
(poll_id
,,updated_at
)created_at
值(10,2020-11-19 11:49: 32, 2020-11-19 11:49:32))'