Laravel8x:don';t使用工厂的轮询id创建FK
我有两个模型Poll和DuplicatePoll 各表如下:Laravel8x:don';t使用工厂的轮询id创建FK,laravel,factory,laravel-8,tinker,Laravel,Factory,Laravel 8,Tinker,我有两个模型Poll和DuplicatePoll 各表如下: Schema::create('polls', function (Blueprint $table) { $table->id(); $table->text('status'); $table->timestamps(); }); Schema::create('duplicate_polls', function (Blueprin
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\u id'=>10]);
PHP致命错误:在第1行的Psy Shell代码中未找到类“App/Models/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(),
];
}
}
如果在
字段中没有更新的,则必须将模型配置为不自动使用该时间戳字段,您指的是哪种模型?可以举个例子吗?