小编Moh*_*sin的帖子

如何在数据库中除公共模式之外的不同模式中插入数据。[拉维尔]

我想将数据插入我在 laravel 迁移中创建的模式中,但我找不到方法。

有人可以指导一下吗?

public function up()
{
    DB::statement('CREATE SCHEMA IF NOT EXISTS reports');

    Schema::create('reports.campaign_reports', function (Blueprint $table) 
     {
        $table->bigIncrements('id');
        $table->string('campaign')->nullable();
        $table->string('currency')->nullable();
    });
}
Run Code Online (Sandbox Code Playgroud)

这是我的模型:

class CampaignReport extends Model
{

//    protected $connection = 'schema.reports';

protected $table = 'campaign_reports';

protected $fillable = [
    'campaign',
    'currency'
    ];
}
Run Code Online (Sandbox Code Playgroud)

这就是我节省的方式:

CampaignReport::create((array) $dataObject);
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

SQLSTATE[42P01]:未定义表:7错误:关系“campaign_reports”不存在第1行:插入“campaign_reports”(“campaign”,“currency”,...

在此输入图像描述

php database migration laravel eloquent

1
推荐指数
1
解决办法
3643
查看次数

标签 统计

database ×1

eloquent ×1

laravel ×1

migration ×1

php ×1