From 4833edb7d632ebee5d0e4510f539c8b331eb5163 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Tue, 21 Apr 2020 10:19:25 -0500 Subject: [PATCH] Don't access the database too soon in Device model boot (#11453) * Don't access the DB in Device model boot * check if db is migrated * use self * revert sensor link change --- app/Models/Device.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Models/Device.php b/app/Models/Device.php index d1a430e492..ebbb792cb1 100644 --- a/app/Models/Device.php +++ b/app/Models/Device.php @@ -9,6 +9,7 @@ use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Database\Query\JoinClause; use Illuminate\Support\Collection; use Illuminate\Support\Str; +use LibreNMS\DB\Schema; use LibreNMS\Exceptions\InvalidIpException; use LibreNMS\Util\IP; use LibreNMS\Util\IPv4; @@ -35,7 +36,9 @@ class Device extends BaseModel public static function boot() { parent::boot(); - self::loadAllOs(true); + if (Schema::isCurrent()) { + self::loadAllOs(true); + } static::deleting(function (Device $device) { // delete related data