Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在数据库中插入除公共模式以外的其他模式中的数据。[拉威尔]_Php_Database_Laravel_Eloquent_Migration - Fatal编程技术网

Php 如何在数据库中插入除公共模式以外的其他模式中的数据。[拉威尔]

Php 如何在数据库中插入除公共模式以外的其他模式中的数据。[拉威尔],php,database,laravel,eloquent,migration,Php,Database,Laravel,Eloquent,Migration,我想在laravel迁移中创建的模式中插入数据,但找不到方法 有人能给我引路吗 public function up() { DB::statement('CREATE SCHEMA IF NOT EXISTS reports'); Schema::create('reports.campaign_reports', function (Blueprint $table) { $table->bigIncrements('id');

我想在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();
    });
}
这是我的模型:

class CampaignReport extends Model
{

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

protected $table = 'campaign_reports';

protected $fillable = [
    'campaign',
    'currency'
    ];
}
这就是我储蓄的方式:

CampaignReport::create((array) $dataObject);
我得到这个错误:

SQLSTATE[42P01]:未定义的表:7错误:关系活动报告不存在第1行:插入到活动报告活动、货币


尝试在数据库配置中定义第二个数据库连接:

/**config/database.php*/ // ... “连接”=>[ “公共_架构”=>[ “驱动程序”=>“pgsql”, 'database'=>env'DB_database', // ... “架构”=>“公共”, ], “报告”\u shema'=>[ “驱动程序”=>“pgsql”, 'database'=>env'DB_database', // ... “架构”=>“报告”, ], ], // ... 然后,在模型中设置连接这对于执行雄辩/查询生成器操作非常有用:

类报告扩展了模型 { 受保护的$connection='reports_schema';//创建'campaign_reports',函数蓝图$t ^^^^^^^^^^^^^^^^^^^^^^^^^^^ { $t->big递增'id'; $t->string'campaign'->可为空; $t->string'currency'->可为空; }; } 顺便说一句,将.env默认数据库密钥更新为:

DB\u连接=公共\u架构
你想手动存储数据还是用户输入?我正在点击谷歌广告api并返回我的数据。我不使用表单或用户输入。只想存储来自该请求的数据。当我使用公共模式默认方式时,它可以工作,但现在我想存储在不同的模式中。那么,我应该在我的env文件中提供什么呢?现在是DB_CONNECTION=pgsql这是因为只要没有指定,Laravel就需要一个默认连接来使用。在您运行的迁移中,如果使用使用公共模式的默认conecction,我认为这就是错误的根源。顺便说一句,在您的.env:DB_CONNECTION=public_schema'中,我在database.php和migrations and model中添加了一些内容,但是我得到了以下错误:InvalidArgumentException:database[reports_schema]未配置。@Mohsin数据库名称必须相同,这就是为什么我在这两个数据库中都使用EVN'DB_DATABASE'